List of usage examples for org.bouncycastle.asn1.pkcs RSAPrivateKey RSAPrivateKey
public RSAPrivateKey(BigInteger modulus, BigInteger publicExponent, BigInteger privateExponent,
BigInteger prime1, BigInteger prime2, BigInteger exponent1, BigInteger exponent2,
BigInteger coefficient)
From source file:co.lqnt.lockbox.key.PrivateKey.java
License:Open Source License
/** * Get the Bouncy Castle RSA private key. * * @return The BouncyCastle RSA private key. *///from www .j a v a 2s . c om public RSAPrivateKey bcPrivateKey() { return new RSAPrivateKey(this.modulus(), this.publicExponent(), this.privateExponent(), this.prime1(), this.prime2(), this.primeExponent1(), this.primeExponent2(), this.coefficient()); }
From source file:org.opcfoundation.ua.transport.security.BcCryptoProvider.java
License:Open Source License
@Override public int decryptAsymm(PrivateKey decryptingKey, SecurityAlgorithm algorithm, byte[] dataToDecrypt, byte[] output, int outputOffset) throws ServiceResultException { java.security.interfaces.RSAPrivateCrtKey rsaPrivateKey = (java.security.interfaces.RSAPrivateCrtKey) decryptingKey; RSAPrivateKey privateKey = new RSAPrivateKey(rsaPrivateKey.getModulus(), rsaPrivateKey.getPublicExponent(), rsaPrivateKey.getPrivateExponent(), rsaPrivateKey.getPrimeP(), rsaPrivateKey.getPrimeQ(), rsaPrivateKey.getPrimeExponentP(), rsaPrivateKey.getPrimeExponentQ(), rsaPrivateKey.getCrtCoefficient()); AsymmetricBlockCipher cipher = getAsymmetricCipher(algorithm, privateKey); try {/*from ww w . java 2s. c om*/ int len = 0; int inputBlockSize = cipher.getInputBlockSize(); int outputBlockSize = cipher.getOutputBlockSize(); logger.debug("Decrypt: inputBlockSize={}, outputBlockSize={}, dataToDecrypt.length={}", inputBlockSize, outputBlockSize, dataToDecrypt.length); for (int i = 0; i < dataToDecrypt.length; i += inputBlockSize) { int size = Math.min(dataToDecrypt.length - i, inputBlockSize); byte[] tmp = cipher.processBlock(dataToDecrypt, i, size); System.arraycopy(tmp, 0, output, outputOffset + len, tmp.length); len += tmp.length; } return len; } catch (CryptoException e) { throw new ServiceResultException(StatusCodes.Bad_InternalError, e); } }
From source file:org.opcfoundation.ua.transport.security.BcCryptoProvider.java
License:Open Source License
@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 {//from w w w . j a v a 2 s . co m 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); } }
From source file:org.xipki.security.bcext.BCRSAPrivateCrtKey.java
License:Open Source License
/** * Return a PKCS8 representation of the key. The sequence returned * represents a full PrivateKeyInfo object. * * @return a PKCS8 representation of the key. *///from w w w .j a v a2 s.c om public byte[] getEncoded() { AlgorithmIdentifier algId = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE); RSAPrivateKey key = new RSAPrivateKey(getModulus(), getPublicExponent(), getPrivateExponent(), getPrimeP(), getPrimeQ(), getPrimeExponentP(), getPrimeExponentQ(), getCrtCoefficient()); return KeyUtil.getEncodedPrivateKeyInfo(algId, key); }