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( Object obj) { if (obj instanceof RSAPrivateKey) { return (RSAPrivateKey)obj; } if (obj != null) { return new RSAPrivateKey(ASN1Sequence.getInstance(obj)); } return null; }
public byte[] getEncoded() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new org.bouncycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO)); }
public byte[] getEncoded() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new org.bouncycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO)); }
RSAPrivateKey privateKey = new RSAPrivateKey( rsaPrivateKey.getModulus(), rsaPrivateKey.getPublicExponent(), rsaPrivateKey.getPrivateExponent(), rsaPrivateKey.getPrimeP(),
/** * Return a PKCS8 representation of the key. The sequence returned * represents a full PrivateKeyInfo object. * * @return a PKCS8 representation of the key. */ public byte[] getEncoded() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPrivateKey(getModulus(), getPublicExponent(), getPrivateExponent(), getPrimeP(), getPrimeQ(), getPrimeExponentP(), getPrimeExponentQ(), getCrtCoefficient())); }
/** * Return a PKCS8 representation of the key. The sequence returned * represents a full PrivateKeyInfo object. * * @return a PKCS8 representation of the key. */ public byte[] getEncoded() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPrivateKey(getModulus(), getPublicExponent(), getPrivateExponent(), getPrimeP(), getPrimeQ(), getPrimeExponentP(), getPrimeExponentQ(), getCrtCoefficient())); }
/** {@inheritDoc} */ @Override public byte[] signAsymm(PrivateKey senderPrivate, SecurityAlgorithm algorithm, byte[] dataToSign) throws ServiceResultException { if (algorithm == null) return null; if (dataToSign == null || senderPrivate == null) throw new IllegalArgumentException("null arg"); java.security.interfaces.RSAPrivateCrtKey privateKey = (java.security.interfaces.RSAPrivateCrtKey) senderPrivate; RSAPrivateKey privKey = new RSAPrivateKey(privateKey.getModulus(), privateKey.getPublicExponent(), privateKey.getPrivateExponent(), privateKey.getPrimeP(), privateKey.getPrimeQ(), privateKey.getPrimeExponentP(), privateKey.getPrimeExponentQ(), privateKey.getCrtCoefficient()); Signer signer = getAsymmetricSigner(true, algorithm, privKey); signer.update(dataToSign, 0, dataToSign.length); try { return signer.generateSignature(); } catch (DataLengthException e) { logger.error("Input data is not an even number of encryption blocks."); throw new ServiceResultException( StatusCodes.Bad_InternalError, "Error in symmetric decrypt: Input data is not an even number of encryption blocks."); } catch (CryptoException e) { throw new ServiceResultException(StatusCodes.Bad_InternalError, e); } }
@Override public KeyPair rsaGenerate() { RSAKeyPairGenerator keyGen = new RSAKeyPairGenerator(); keyGen.init(new RSAKeyGenerationParameters(E, new SecureRandom(), RSA_KEY_SIZE, PrimeCertaintyCalculator.getDefaultCertainty(RSA_KEY_SIZE))); AsymmetricCipherKeyPair pair = keyGen.generateKeyPair(); RSAKeyParameters pub = (RSAKeyParameters)pair.getPublic(); RSAPrivateCrtKeyParameters priv = (RSAPrivateCrtKeyParameters)pair.getPrivate(); // As in BCRSAPrivateKey / BCRSAPublicKey AlgorithmIdentifier algo = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE); byte[] publicKey = KeyUtil.getEncodedSubjectPublicKeyInfo(algo, new RSAPublicKey(pub.getModulus(), pub.getExponent())); byte[] privateKey = KeyUtil.getEncodedPrivateKeyInfo(algo, new RSAPrivateKey(priv.getModulus(), priv.getPublicExponent(), priv.getExponent(), priv.getP(), priv.getQ(), priv.getDP(), priv.getDQ(), priv.getQInv())); return new KeyPair(privateKey, publicKey); } }
return new PrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPrivateKey(priv.getModulus(), priv.getPublicExponent(), priv.getExponent(), priv.getP(), priv.getQ(), priv.getDP(), priv.getDQ(), priv.getQInv()));
new RSAPrivateKey(priv.getModulus(), priv.getPublicExponent(), priv.getPrivateExponent(), priv.getPrimeP(), priv.getPrimeQ(),
new RSAPrivateKey(priv.getModulus(), priv.getPublicExponent(), priv.getExponent(), priv.getP(), priv.getQ(), priv.getDP(), priv.getDQ(), priv.getQInv()), attributes);