Example usage for org.bouncycastle.asn1.x509 RSAPublicKeyStructure getInstance

List of usage examples for org.bouncycastle.asn1.x509 RSAPublicKeyStructure getInstance

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 RSAPublicKeyStructure getInstance.

Prototype

public static RSAPublicKeyStructure getInstance(Object obj) 

Source Link

Usage

From source file:ezbake.crypto.RSAKeyCrypto.java

License:Apache License

private static PublicKey fixPubKey(byte[] orig) throws InvalidKeySpecException, NoSuchAlgorithmException {
    try {/*from w  w  w . j  a  v  a2  s .  co  m*/
        ASN1InputStream in = new ASN1InputStream(orig);

        ASN1Primitive obj = in.readObject();
        RSAPublicKeyStructure keyStruct = RSAPublicKeyStructure.getInstance(obj);
        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(keyStruct.getModulus(), keyStruct.getPublicExponent());
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        return keyFactory.generatePublic(keySpec);
    } catch (IOException e) {
        throw new InvalidKeySpecException("Unable to load public key with stopgap ASN1 method", e);
    }
}

From source file:org.opensc.pkcs15.asn1.attr.RSAPublicKeyChoice.java

License:Apache License

static public RSAPublicKeyChoice getInstance(Object obj) {

    if (obj instanceof RSAPublicKeyChoice)
        return (RSAPublicKeyChoice) obj;

    if (obj instanceof SubjectPublicKeyInfo)
        return new RSAPublicKeyChoice((SubjectPublicKeyInfo) obj);

    if (obj instanceof RSAPublicKeyStructure)
        return new RSAPublicKeyChoice((RSAPublicKeyStructure) obj);

    if (obj instanceof ASN1Sequence)
        return new RSAPublicKeyChoice(RSAPublicKeyStructure.getInstance(obj));

    if (obj instanceof ASN1TaggedObject) {

        ASN1TaggedObject to = (ASN1TaggedObject) obj;

        if (to.getTagNo() != 1)
            throw new IllegalArgumentException(
                    "Invalid member tag [" + to.getTagNo() + "] in RSAPublicKeyChoice.");

        return new RSAPublicKeyChoice(SubjectPublicKeyInfo.getInstance(to.getObject()));
    }/*from w  ww .j a v a  2 s  .  c o m*/

    throw new IllegalArgumentException("Invalid RSAPublicKeyChoice.");
}