/** * construct an RSA key from a ASN.1 RSA private key object. */ JCERSAPrivateCrtKey( RSAPrivateKey key) { this.modulus = key.getModulus(); this.publicExponent = key.getPublicExponent(); this.privateExponent = key.getPrivateExponent(); this.primeP = key.getPrime1(); this.primeQ = key.getPrime2(); this.primeExponentP = key.getExponent1(); this.primeExponentQ = key.getExponent2(); this.crtCoefficient = key.getCoefficient(); }
public static RSAPrivateKey getInstance( Object obj) { if (obj instanceof RSAPrivateKey) { return (RSAPrivateKey)obj; } if (obj != null) { return new RSAPrivateKey(ASN1Sequence.getInstance(obj)); } return null; }
/** * construct an RSA key from a private key info object. */ BCRSAPrivateCrtKey( PrivateKeyInfo info) throws IOException { this(RSAPrivateKey.getInstance(info.parsePrivateKey())); }
BCRSAPrivateKey(org.spongycastle.asn1.pkcs.RSAPrivateKey key) { this.modulus = key.getModulus(); this.privateExponent = key.getPrivateExponent(); }
public PEMKeyPair parse(byte[] encoding) throws IOException { try { ASN1Sequence seq = ASN1Sequence.getInstance(encoding); if (seq.size() != 9) { throw new PEMException("malformed sequence in RSA private key"); } org.spongycastle.asn1.pkcs.RSAPrivateKey keyStruct = org.spongycastle.asn1.pkcs.RSAPrivateKey.getInstance(seq); RSAPublicKey pubSpec = new RSAPublicKey( keyStruct.getModulus(), keyStruct.getPublicExponent()); AlgorithmIdentifier algId = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE); return new PEMKeyPair(new SubjectPublicKeyInfo(algId, pubSpec), new PrivateKeyInfo(algId, keyStruct)); } catch (IOException e) { throw e; } catch (Exception e) { throw new PEMException( "problem creating RSA private key: " + e.toString(), e); } } }
public PrivateKey generatePrivate(PrivateKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getPrivateKeyAlgorithm().getAlgorithm(); if (RSAUtil.isRsaOid(algOid)) { RSAPrivateKey rsaPrivKey = RSAPrivateKey.getInstance(keyInfo.parsePrivateKey()); if (rsaPrivKey.getCoefficient().intValue() == 0) { return new BCRSAPrivateKey(rsaPrivKey); } else { return new BCRSAPrivateCrtKey(keyInfo); } } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } }
@Override public byte[] getEncoded() throws TelehashException { org.spongycastle.asn1.pkcs.RSAPrivateKey asn1Key; asn1Key = new org.spongycastle.asn1.pkcs.RSAPrivateKey( mKey.getModulus(), mKey.getPublicExponent(), mKey.getExponent(), mKey.getP(), mKey.getQ(), mKey.getDP(), mKey.getDQ(), mKey.getQInv() ); try { return asn1Key.getEncoded("DER"); } catch (IOException e) { throw new TelehashException(e); } }
public PEMKeyPair parse(byte[] encoding) throws IOException { try { ASN1Sequence seq = ASN1Sequence.getInstance(encoding); if (seq.size() != 9) { throw new PEMException("malformed sequence in RSA private key"); } org.spongycastle.asn1.pkcs.RSAPrivateKey keyStruct = org.spongycastle.asn1.pkcs.RSAPrivateKey.getInstance(seq); RSAPublicKey pubSpec = new RSAPublicKey( keyStruct.getModulus(), keyStruct.getPublicExponent()); AlgorithmIdentifier algId = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE); return new PEMKeyPair(new SubjectPublicKeyInfo(algId, pubSpec), new PrivateKeyInfo(algId, keyStruct)); } catch (IOException e) { throw e; } catch (Exception e) { throw new PEMException( "problem creating RSA private key: " + e.toString(), e); } } }
/** * construct an RSA key from a ASN.1 RSA private key object. */ BCRSAPrivateCrtKey( RSAPrivateKey key) { this.modulus = key.getModulus(); this.publicExponent = key.getPublicExponent(); this.privateExponent = key.getPrivateExponent(); this.primeP = key.getPrime1(); this.primeQ = key.getPrime2(); this.primeExponentP = key.getExponent1(); this.primeExponentQ = key.getExponent2(); this.crtCoefficient = key.getCoefficient(); }
public static RSAPrivateKey getInstance( Object obj) { if (obj instanceof RSAPrivateKey) { return (RSAPrivateKey)obj; } if (obj != null) { return new RSAPrivateKey(ASN1Sequence.getInstance(obj)); } return null; }
public static RSAPrivateKey getInstance( ASN1TaggedObject obj, boolean explicit) { return getInstance(ASN1Sequence.getInstance(obj, explicit)); }
/** * construct an RSA key from a ASN.1 RSA private key object. */ JCERSAPrivateCrtKey( RSAPrivateKey key) { this.modulus = key.getModulus(); this.publicExponent = key.getPublicExponent(); this.privateExponent = key.getPrivateExponent(); this.primeP = key.getPrime1(); this.primeQ = key.getPrime2(); this.primeExponentP = key.getExponent1(); this.primeExponentQ = key.getExponent2(); this.crtCoefficient = key.getCoefficient(); }
public byte[] getEncoded() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new org.spongycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO)); }
/** * construct an RSA key from a private key info object. */ JCERSAPrivateCrtKey( PrivateKeyInfo info) throws IOException { this(org.spongycastle.asn1.pkcs.RSAPrivateKey.getInstance(info.parsePrivateKey())); }
/** * construct an RSA key from a ASN.1 RSA private key object. */ BCRSAPrivateCrtKey( RSAPrivateKey key) { this.modulus = key.getModulus(); this.publicExponent = key.getPublicExponent(); this.privateExponent = key.getPrivateExponent(); this.primeP = key.getPrime1(); this.primeQ = key.getPrime2(); this.primeExponentP = key.getExponent1(); this.primeExponentQ = key.getExponent2(); this.crtCoefficient = key.getCoefficient(); }
public byte[] getEncoded() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new org.spongycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO)); }
/** * construct an RSA key from a private key info object. */ JCERSAPrivateCrtKey( PrivateKeyInfo info) throws IOException { this(org.spongycastle.asn1.pkcs.RSAPrivateKey.getInstance(info.parsePrivateKey())); }
private AsymmetricBlockCipher getAsymmetricCipher( SecurityAlgorithm algorithm, RSAPrivateKey privateKey) throws ServiceResultException { CipherParameters params = new RSAPrivateCrtKeyParameters( privateKey.getModulus(), privateKey.getPublicExponent(), privateKey.getPrivateExponent(), privateKey.getPrime1(), privateKey.getPrime2(), privateKey.getExponent1(), privateKey.getExponent2(), privateKey.getCoefficient()); return getAsymmetricCipher(false, algorithm, params); }
public byte[] getEncoded() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new org.spongycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO)); }
/** * construct an RSA key from a private key info object. */ BCRSAPrivateCrtKey( PrivateKeyInfo info) throws IOException { this(RSAPrivateKey.getInstance(info.parsePrivateKey())); }