ASN1Sequence seq = ASN1Sequence.getInstance(content); org.bouncycastle.asn1.pkcs.RSAPublicKey key = org.bouncycastle.asn1.pkcs.RSAPublicKey.getInstance(seq); RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(key.getModulus(), key.getPublicExponent()); publicKey = fact.generatePublic(pubSpec); } else {
ASN1Sequence seq = ASN1Sequence.getInstance(content); org.bouncycastle.asn1.pkcs.RSAPublicKey key = org.bouncycastle.asn1.pkcs.RSAPublicKey.getInstance(seq); RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(key.getModulus(), key.getPublicExponent()); publicKey = fact.generatePublic(pubSpec); } else {
JCERSAPublicKey( SubjectPublicKeyInfo info) { try { org.bouncycastle.asn1.pkcs.RSAPublicKey pubKey = org.bouncycastle.asn1.pkcs.RSAPublicKey.getInstance(info.parsePublicKey()); this.modulus = pubKey.getModulus(); this.publicExponent = pubKey.getPublicExponent(); } catch (IOException e) { throw new IllegalArgumentException("invalid info structure in RSA public key"); } }
public static PublicKey getRSAPublicKey(byte[] encodedPubKey) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { RSAPublicKey pubKey8 = RSAPublicKey.getInstance(encodedPubKey); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(new RSAKeyParameters(false, pubKey8.getModulus(), pubKey8.getPublicExponent())); X509EncodedKeySpec spec = new X509EncodedKeySpec(info.getEncoded()); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); return keyFactory.generatePublic(spec); }
public static PublicKey getRSAPublicKey(byte[] encodedPubKey) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { RSAPublicKey pubKey8 = RSAPublicKey.getInstance(encodedPubKey); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(new RSAKeyParameters(false, pubKey8.getModulus(), pubKey8.getPublicExponent())); X509EncodedKeySpec spec = new X509EncodedKeySpec(info.getEncoded()); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); return keyFactory.generatePublic(spec); }
private AsymmetricBlockCipher getAsymmetricCipher( SecurityAlgorithm algorithm, RSAPublicKey publicKey) throws ServiceResultException { CipherParameters params = new RSAKeyParameters(false, publicKey.getModulus(), publicKey.getPublicExponent()); // logger.info("Cipher: \nmodulus={}, \npublicExponent={}\n", // publicKey.getModulus(), publicKey.getPublicExponent()); return getAsymmetricCipher(true, algorithm, params); }
private Signer getAsymmetricSigner(boolean forSigning, SecurityAlgorithm algorithm, RSAPublicKey publicKey) throws ServiceResultException { CipherParameters params = new RSAKeyParameters(false, publicKey.getModulus(), publicKey.getPublicExponent()); return getAsymmetricSigner(forSigning, algorithm, params); }
private void populateFromPublicKeyInfo(SubjectPublicKeyInfo info) { try { org.bouncycastle.asn1.pkcs.RSAPublicKey pubKey = org.bouncycastle.asn1.pkcs.RSAPublicKey.getInstance(info.parsePublicKey()); this.algorithmIdentifier = info.getAlgorithm(); this.modulus = pubKey.getModulus(); this.publicExponent = pubKey.getPublicExponent(); } catch (IOException e) { throw new IllegalArgumentException("invalid info structure in RSA public key"); } }
AsymmetricKeyParameter getPublicKeyParameters(SubjectPublicKeyInfo keyInfo, Object defaultParams) throws IOException { RSAPublicKey pubKey = RSAPublicKey.getInstance(keyInfo.parsePublicKey()); return new RSAKeyParameters(false, pubKey.getModulus(), pubKey.getPublicExponent()); } }
ASN1Sequence seq = ASN1Sequence.getInstance(content); org.bouncycastle.asn1.pkcs.RSAPublicKey key = org.bouncycastle.asn1.pkcs.RSAPublicKey.getInstance(seq); RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(key.getModulus(), key.getPublicExponent()); publicKey = fact.generatePublic(pubSpec); } else {
org.bouncycastle.asn1.pkcs.RSAPublicKey key = org.bouncycastle.asn1.pkcs.RSAPublicKey .getInstance(seq); RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(key.getModulus(), key.getPublicExponent()); publicKey = fact.generatePublic(pubSpec);
/** * This outputs the key in PKCS1v2 format. * <pre> * RSAPublicKey ::= SEQUENCE { * modulus INTEGER, -- n * publicExponent INTEGER, -- e * } * </pre> * <p> */ public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new ASN1Integer(getModulus())); v.add(new ASN1Integer(getPublicExponent())); return new DERSequence(v); } }
/** * This outputs the key in PKCS1v2 format. * <pre> * RSAPublicKey ::= SEQUENCE { * modulus INTEGER, -- n * publicExponent INTEGER, -- e * } * </pre> * <p> */ public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new ASN1Integer(getModulus())); v.add(new ASN1Integer(getPublicExponent())); return new DERSequence(v); } }
return new RSAKeyParameters(false, pubKey.getModulus(), pubKey.getPublicExponent());