protected AsymmetricBlockCipher createAsymmetricWrapper(ASN1ObjectIdentifier algorithm) { return new PKCS1Encoding(new RSAEngine()); } }
protected AsymmetricBlockCipher createAsymmetricUnwrapper(ASN1ObjectIdentifier algorithm) { return new PKCS1Encoding(new RSAEngine()); } }
protected AsymmetricBlockCipher createAsymmetricWrapper(ASN1ObjectIdentifier algorithm) { return new PKCS1Encoding(new RSAEngine()); } }
protected AsymmetricBlockCipher createAsymmetricUnwrapper(ASN1ObjectIdentifier algorithm) { return new PKCS1Encoding(new RSAEngine()); } }
/** * Create the {@link RSAEngine} implementation using the best possible optimization. */ public static RSAEngine make() { return (shouldUseNative) ? new NativeRSAEngine() : new RSAEngine(); }
private AsymmetricBlockCipher getAsymmetricCipher(boolean forEncryption, SecurityAlgorithm algorithm, CipherParameters params) throws ServiceResultException { AsymmetricBlockCipher cipher = null; if (algorithm.equals(SecurityAlgorithm.Rsa15)) { cipher = new PKCS1Encoding(new RSAEngine()); } else if (algorithm.equals(SecurityAlgorithm.RsaOaep)) { cipher = new OAEPEncoding(new RSAEngine(), new SHA1Digest()); } else if (algorithm.equals(SecurityAlgorithm.RsaOaep256)) { cipher = new OAEPEncoding(new RSAEngine(), new SHA256Digest()); } else { throw new ServiceResultException( StatusCodes.Bad_SecurityPolicyRejected, "Unsupported asymmetric encryption algorithm: " + algorithm); } cipher.init(forEncryption, params); return cipher; }
/** * Encrypt data with an RSA private key using OAEP padding * @throws TelehashException */ @Override public byte[] encryptRSAOAEP(HashNamePublicKey key, byte[] clearText) throws TelehashException { AsymmetricBlockCipher cipher = new OAEPEncoding(new RSAEngine(), new SHA1Digest()); cipher.init(true, ((HashNamePublicKeyImpl)key).getKey()); byte[] cipherText; try { cipherText = cipher.processBlock(clearText, 0, clearText.length); } catch (InvalidCipherTextException e) { throw new TelehashException(e); } return cipherText; }
/** * Decrypt data with an RSA private key and OAEP padding * @throws TelehashException */ @Override public byte[] decryptRSAOAEP( HashNamePrivateKey key, byte[] cipherText ) throws TelehashException { AsymmetricBlockCipher cipher = new OAEPEncoding(new RSAEngine(), new SHA1Digest()); cipher.init(false, ((HashNamePrivateKeyImpl)key).getKey()); byte[] clearText; try { clearText = cipher.processBlock(cipherText, 0, cipherText.length); } catch (InvalidCipherTextException e) { throw new TelehashException(e); } return clearText; }
private Signer getAsymmetricSigner(boolean forSigning, SecurityAlgorithm algorithm, CipherParameters params) throws ServiceResultException { Signer signer = null; if (algorithm.equals(SecurityAlgorithm.RsaSha1)) { signer = new RSADigestSigner(new SHA1Digest()); } else if (algorithm.equals(SecurityAlgorithm.RsaSha256)) { signer = new RSADigestSigner(new SHA256Digest()); } else if (algorithm.equals(SecurityAlgorithm.RsaPssSha256)) { signer = new PSSSigner(new RSAEngine(), new SHA256Digest(), 32); } else { throw new ServiceResultException( StatusCodes.Bad_SecurityPolicyRejected, "Unsupported asymmetric signature algorithm: " + algorithm); } signer.init(forSigning, params); return signer; }