/** * Reset the decrypting RSA engine, restarting any decryption flow from the beginning. */ void resetDecryptor() { if (state == null) { throw new IllegalStateException(); } else { state.decryptor.init(false, new ParametersWithRandom(state.keyParameters, state.rng)); } }
/** * Reset the encrypting RSA engine, restarting any encryption flow from the beginning. */ void resetEncryptor() { if (state == null) { throw new IllegalStateException(); } else { state.encryptor.init(true, new ParametersWithRandom(state.keyParameters, state.rng)); } }
protected void initCipherEncrypt(Key key, AlgorithmParameterSpec params, SecureRandom sr) throws InvalidKeyException, InvalidAlgorithmParameterException { CipherParameters param; param = McElieceKeysToParams.generatePublicKeyParameter((PublicKey)key); param = new ParametersWithRandom(param, sr); cipher.init(true, param); this.maxPlainTextSize = cipher.maxPlainTextSize; this.cipherTextSize = cipher.cipherTextSize; }
public Signer createSigner(SignatureAndHashAlgorithm algorithm, AsymmetricKeyParameter privateKey) { return makeSigner(algorithm, false, true, new ParametersWithRandom(privateKey, this.context.getSecureRandom())); }
protected void initCipherEncrypt(Key key, AlgorithmParameterSpec params, SecureRandom sr) throws InvalidKeyException, InvalidAlgorithmParameterException { buf.reset(); CipherParameters param; param = McElieceCCA2KeysToParams.generatePublicKeyParameter((PublicKey)key); param = new ParametersWithRandom(param, sr); digest.reset(); cipher.init(true, param); }
protected void engineInitSign( PrivateKey privateKey) throws InvalidKeyException { CipherParameters param = DSAUtil.generatePrivateKeyParameter(privateKey); if (random != null) { param = new ParametersWithRandom(param, random); } digest.reset(); signer.init(true, param); }
protected void initCipherEncrypt(Key key, AlgorithmParameterSpec params, SecureRandom sr) throws InvalidKeyException, InvalidAlgorithmParameterException { CipherParameters param; param = McElieceCCA2KeysToParams.generatePublicKeyParameter((PublicKey)key); param = new ParametersWithRandom(param, sr); digest.reset(); cipher.init(true, param); }
protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException { CipherParameters param; param = RainbowKeysToParams.generatePrivateKeyParameter(privateKey); if (random != null) { param = new ParametersWithRandom(param, random); } digest.reset(); signer.init(true, param); }
protected void initCipherEncrypt(Key key, AlgorithmParameterSpec params, SecureRandom sr) throws InvalidKeyException, InvalidAlgorithmParameterException { CipherParameters param; param = McElieceCCA2KeysToParams.generatePublicKeyParameter((PublicKey)key); param = new ParametersWithRandom(param, sr); digest.reset(); cipher.init(true, param); }
protected void engineInitSign( PrivateKey privateKey, SecureRandom random) throws InvalidKeyException { if (!(privateKey instanceof RSAPrivateKey)) { throw new InvalidKeyException("Supplied key is not a RSAPrivateKey instance"); } pss = new org.spongycastle.crypto.signers.PSSSigner(signer, contentDigest, mgfDigest, saltLength, trailer); pss.init(true, new ParametersWithRandom(RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey), random)); }
protected void engineInitSign( PrivateKey privateKey, SecureRandom random) throws InvalidKeyException { if (!(privateKey instanceof RSAPrivateKey)) { throw new InvalidKeyException("Supplied key is not a RSAPrivateKey instance"); } pss = new org.spongycastle.crypto.signers.PSSSigner(signer, contentDigest, mgfDigest, saltLength, trailer); pss.init(true, new ParametersWithRandom(RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey), random)); }
public byte[] generateRawSignature(SignatureAndHashAlgorithm algorithm, AsymmetricKeyParameter privateKey, byte[] hash) throws CryptoException { Signer signer = makeSigner(algorithm, true, true, new ParametersWithRandom(privateKey, this.context.getSecureRandom())); signer.update(hash, 0, hash.length); return signer.generateSignature(); }
protected void engineInitSign( PrivateKey privateKey) throws InvalidKeyException { CipherParameters param = ECUtil.generatePrivateKeyParameter(privateKey); digest.reset(); if (appRandom != null) { signer.init(true, new ParametersWithRandom(param, appRandom)); } else { signer.init(true, param); } }
protected void engineInitSign( PrivateKey privateKey) throws InvalidKeyException { CipherParameters param = ECUtil.generatePrivateKeyParameter(privateKey); digest.reset(); if (appRandom != null) { signer.init(true, new ParametersWithRandom(param, appRandom)); } else { signer.init(true, param); } }
public byte[] generateWrappedKey(GenericKey encryptionKey) throws OperatorException { byte[] contentEncryptionKeySpec = OperatorUtils.getKeyBytes(encryptionKey); if (random == null) { wrapper.init(true, wrappingKey); } else { wrapper.init(true, new ParametersWithRandom(wrappingKey, random)); } return wrapper.wrap(contentEncryptionKeySpec, 0, contentEncryptionKeySpec.length); } }
public byte[] generateWrappedKey(GenericKey encryptionKey) throws OperatorException { byte[] contentEncryptionKeySpec = OperatorUtils.getKeyBytes(encryptionKey); if (random == null) { wrapper.init(true, wrappingKey); } else { wrapper.init(true, new ParametersWithRandom(wrappingKey, random)); } return wrapper.wrap(contentEncryptionKeySpec, 0, contentEncryptionKeySpec.length); } }
public byte[] generateRawSignature(SignatureAndHashAlgorithm algorithm, AsymmetricKeyParameter privateKey, byte[] hash) throws CryptoException { Signer signer = makeSigner(algorithm, true, true, new ParametersWithRandom(privateKey, this.context.getSecureRandom())); if (algorithm == null) { // Note: Only use the SHA1 part of the (MD5/SHA1) hash signer.update(hash, 16, 20); } else { signer.update(hash, 0, hash.length); } return signer.generateSignature(); }
public byte[] calculateRawSignature(SecureRandom secureRandom, AsymmetricKeyParameter privateKey, byte[] md5andsha1) throws CryptoException { // Note: Only use the SHA1 part of the hash Signer signer = new DSADigestSigner(createDSAImpl(), new NullDigest()); signer.init(true, new ParametersWithRandom(privateKey, secureRandom)); signer.update(md5andsha1, 16, 20); return signer.generateSignature(); }
public byte[] calculateRawSignature(SecureRandom random, AsymmetricKeyParameter privateKey, byte[] md5andsha1) throws CryptoException { Signer sig = new GenericSigner(new PKCS1Encoding(new RSABlindedEngine()), new NullDigest()); sig.init(true, new ParametersWithRandom(privateKey, random)); sig.update(md5andsha1, 0, md5andsha1.length); return sig.generateSignature(); }
/** * Make sure the SpongyCastle OAEPEncoding encodes the block according * to the test vectors from RSA OAEP specification. * * @throws Exception */ @Test public void encodeBlock() throws Exception { AsymmetricBlockCipher encoder = new OAEPEncoding(RSAEngineFactory.make()); encoder.init(true, new ParametersWithRandom(oaepSpec.pubParameters, oaepSpec.getRandSeed())); byte[] encoded = encoder.processBlock(oaepSpec.M, 0, oaepSpec.M.length); assertArrayEquals(encoded, oaepSpec.C); }