diff options
author | Sergio Giro <sgiro@google.com> | 2016-02-01 18:54:35 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-02-01 18:54:35 +0000 |
commit | 3e75bd6b407dd472c834a50f16aae54cca67ea9c (patch) | |
tree | b5eb091b97b2aade28e5b45a15352125a4a776d7 /bcprov/src/main/java/org/bouncycastle/crypto/util/SubjectPublicKeyInfoFactory.java | |
parent | 9218edabd1ef9852bc2f13115dcadc81b442dd6c (diff) | |
parent | c1040cb5656c3299f1c2d0fe0bd7c44b10466aaf (diff) | |
download | android_external_bouncycastle-3e75bd6b407dd472c834a50f16aae54cca67ea9c.tar.gz android_external_bouncycastle-3e75bd6b407dd472c834a50f16aae54cca67ea9c.tar.bz2 android_external_bouncycastle-3e75bd6b407dd472c834a50f16aae54cca67ea9c.zip |
Merge "Restoring the contents of aosp after"
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/crypto/util/SubjectPublicKeyInfoFactory.java')
-rw-r--r-- | bcprov/src/main/java/org/bouncycastle/crypto/util/SubjectPublicKeyInfoFactory.java | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/util/SubjectPublicKeyInfoFactory.java b/bcprov/src/main/java/org/bouncycastle/crypto/util/SubjectPublicKeyInfoFactory.java deleted file mode 100644 index d2d4203..0000000 --- a/bcprov/src/main/java/org/bouncycastle/crypto/util/SubjectPublicKeyInfoFactory.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.bouncycastle.crypto.util; - -import java.io.IOException; - -import org.bouncycastle.asn1.ASN1Encodable; -import org.bouncycastle.asn1.ASN1Integer; -import org.bouncycastle.asn1.ASN1OctetString; -import org.bouncycastle.asn1.DERNull; -import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import org.bouncycastle.asn1.pkcs.RSAPublicKey; -import org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import org.bouncycastle.asn1.x9.X962Parameters; -import org.bouncycastle.asn1.x9.X9ECParameters; -import org.bouncycastle.asn1.x9.X9ECPoint; -import org.bouncycastle.asn1.x9.X9ObjectIdentifiers; -import org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import org.bouncycastle.crypto.params.DSAPublicKeyParameters; -import org.bouncycastle.crypto.params.ECDomainParameters; -import org.bouncycastle.crypto.params.ECNamedDomainParameters; -import org.bouncycastle.crypto.params.ECPublicKeyParameters; -import org.bouncycastle.crypto.params.RSAKeyParameters; - -/** - * Factory to create ASN.1 subject public key info objects from lightweight public keys. - */ -public class SubjectPublicKeyInfoFactory -{ - /** - * Create a SubjectPublicKeyInfo public key. - * - * @param publicKey the SubjectPublicKeyInfo encoding - * @return the appropriate key parameter - * @throws java.io.IOException on an error encoding the key - */ - public static SubjectPublicKeyInfo createSubjectPublicKeyInfo(AsymmetricKeyParameter publicKey) throws IOException - { - if (publicKey instanceof RSAKeyParameters) - { - RSAKeyParameters pub = (RSAKeyParameters)publicKey; - - return new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKey(pub.getModulus(), pub.getExponent())); - } - else if (publicKey instanceof DSAPublicKeyParameters) - { - DSAPublicKeyParameters pub = (DSAPublicKeyParameters)publicKey; - - return new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa), new ASN1Integer(pub.getY())); - } - else if (publicKey instanceof ECPublicKeyParameters) - { - ECPublicKeyParameters pub = (ECPublicKeyParameters)publicKey; - ECDomainParameters domainParams = pub.getParameters(); - ASN1Encodable params; - - if (domainParams == null) - { - params = new X962Parameters(DERNull.INSTANCE); // Implicitly CA - } - else if (domainParams instanceof ECNamedDomainParameters) - { - params = new X962Parameters(((ECNamedDomainParameters)domainParams).getName()); - } - else - { - X9ECParameters ecP = new X9ECParameters( - domainParams.getCurve(), - domainParams.getG(), - domainParams.getN(), - domainParams.getH(), - domainParams.getSeed()); - - params = new X962Parameters(ecP); - } - - ASN1OctetString p = (ASN1OctetString)new X9ECPoint(pub.getQ()).toASN1Primitive(); - - return new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params), p.getOctets()); - } - else - { - throw new IOException("key parameters not recognised."); - } - } -} |