use of com.github.zhenwei.pkix.operator.InputDecryptor in project LinLong-Java by zhenwei1108.
the class CMSEncryptedData method getContentStream.
public CMSTypedStream getContentStream(InputDecryptorProvider inputDecryptorProvider) throws CMSException {
try {
EncryptedContentInfo encContentInfo = encryptedData.getEncryptedContentInfo();
InputDecryptor decrytor = inputDecryptorProvider.get(encContentInfo.getContentEncryptionAlgorithm());
ByteArrayInputStream encIn = new ByteArrayInputStream(encContentInfo.getEncryptedContent().getOctets());
return new CMSTypedStream(encContentInfo.getContentType(), decrytor.getInputStream(encIn));
} catch (Exception e) {
throw new CMSException("unable to create stream: " + e.getMessage(), e);
}
}
use of com.github.zhenwei.pkix.operator.InputDecryptor in project LinLong-Java by zhenwei1108.
the class EncryptedValueParser method decryptValue.
private byte[] decryptValue(ValueDecryptorGenerator decGen) throws CRMFException {
if (value.getValueHint() != null) {
throw new UnsupportedOperationException();
}
InputDecryptor decryptor = decGen.getValueDecryptor(value.getKeyAlg(), value.getSymmAlg(), value.getEncSymmKey().getBytes());
InputStream dataIn = decryptor.getInputStream(new ByteArrayInputStream(value.getEncValue().getBytes()));
try {
byte[] data = Streams.readAll(dataIn);
if (padder != null) {
return padder.getUnpaddedData(data);
}
return data;
} catch (IOException e) {
throw new CRMFException("Cannot parse decrypted data: " + e.getMessage(), e);
}
}
use of com.github.zhenwei.pkix.operator.InputDecryptor in project LinLong-Java by zhenwei1108.
the class JceAsymmetricValueDecryptorGenerator method getValueDecryptor.
public InputDecryptor getValueDecryptor(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey) throws CRMFException {
Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, encryptedContentEncryptionKey);
final Cipher dataCipher = helper.createContentCipher(secretKey, contentEncryptionAlgorithm);
return new InputDecryptor() {
public AlgorithmIdentifier getAlgorithmIdentifier() {
return contentEncryptionAlgorithm;
}
public InputStream getInputStream(InputStream dataIn) {
return new CipherInputStream(dataIn, dataCipher);
}
};
}
use of com.github.zhenwei.pkix.operator.InputDecryptor 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.pkix.operator.InputDecryptor in project LinLong-Java by zhenwei1108.
the class JceKEKEnvelopedRecipient method getRecipientOperator.
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey) throws CMSException {
Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, encryptedContentEncryptionKey);
final Cipher dataCipher = contentHelper.createContentCipher(secretKey, contentEncryptionAlgorithm);
return new RecipientOperator(new InputDecryptor() {
public AlgorithmIdentifier getAlgorithmIdentifier() {
return contentEncryptionAlgorithm;
}
public InputStream getInputStream(InputStream dataOut) {
return new CipherInputStream(dataOut, dataCipher);
}
});
}
Aggregations