use of com.github.zhenwei.core.crypto.io.CipherInputStream in project LinLong-Java by zhenwei1108.
the class BcRSAKeyTransEnvelopedRecipient method getRecipientOperator.
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey) throws CMSException {
CipherParameters secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, encryptedContentEncryptionKey);
final Object dataCipher = EnvelopedDataHelper.createContentCipher(false, secretKey, contentEncryptionAlgorithm);
return new RecipientOperator(new InputDecryptor() {
public AlgorithmIdentifier getAlgorithmIdentifier() {
return contentEncryptionAlgorithm;
}
public InputStream getInputStream(InputStream dataIn) {
if (dataCipher instanceof BufferedBlockCipher) {
return new CipherInputStream(dataIn, (BufferedBlockCipher) dataCipher);
} else {
return new CipherInputStream(dataIn, (StreamCipher) dataCipher);
}
}
});
}
use of com.github.zhenwei.core.crypto.io.CipherInputStream in project LinLong-Java by zhenwei1108.
the class BcPKCS12PBEInputDecryptorProviderBuilder method build.
public InputDecryptorProvider build(final char[] password) {
return new InputDecryptorProvider() {
public InputDecryptor get(final AlgorithmIdentifier algorithmIdentifier) {
final PaddedBufferedBlockCipher engine = PKCS12PBEUtils.getEngine(algorithmIdentifier.getAlgorithm());
PKCS12PBEParams pbeParams = PKCS12PBEParams.getInstance(algorithmIdentifier.getParameters());
CipherParameters params = PKCS12PBEUtils.createCipherParameters(algorithmIdentifier.getAlgorithm(), digest, engine.getBlockSize(), pbeParams, password);
engine.init(false, params);
return new InputDecryptor() {
public AlgorithmIdentifier getAlgorithmIdentifier() {
return algorithmIdentifier;
}
public InputStream getInputStream(InputStream input) {
return new CipherInputStream(input, engine);
}
public GenericKey getKey() {
return new GenericKey(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
}
};
}
};
}
use of com.github.zhenwei.core.crypto.io.CipherInputStream in project LinLong-Java by zhenwei1108.
the class BcPasswordEnvelopedRecipient method getRecipientOperator.
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] derivedKey, byte[] encryptedContentEncryptionKey) throws CMSException {
KeyParameter secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, derivedKey, encryptedContentEncryptionKey);
final Object dataCipher = EnvelopedDataHelper.createContentCipher(false, secretKey, contentEncryptionAlgorithm);
return new RecipientOperator(new InputDecryptor() {
public AlgorithmIdentifier getAlgorithmIdentifier() {
return contentEncryptionAlgorithm;
}
public InputStream getInputStream(InputStream dataOut) {
if (dataCipher instanceof BufferedBlockCipher) {
return new CipherInputStream(dataOut, (BufferedBlockCipher) dataCipher);
} else {
return new CipherInputStream(dataOut, (StreamCipher) dataCipher);
}
}
});
}
Aggregations