use of com.bluenimble.platform.crypto.tests.KeyInformation in project serverless by bluenimble.
the class DecryptDocument method main.
public static void main(String[] args) throws IOException, CertificateException, UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, CertStoreException, CMSException, NoSuchPaddingException, InvalidKeyException, ShortBufferException, IllegalBlockSizeException, BadPaddingException {
CMSEnvelopedData ced = new CMSEnvelopedData(new FileInputStream("ToBeDecrypted.pk7"));
Collection<?> recip = ced.getRecipientInfos().getRecipients();
KeyTransRecipientInformation rinfo = (KeyTransRecipientInformation) recip.iterator().next();
// privatekey est la cl� priv�e permettant de d�chiffrer la cl� secr�te (sym�trique)
// "2[$0wUOS";
String password = "bspass";
// "thawte freemail member's thawte consulting (pty) ltd. id";
String alias = "bscert";
KeyInformation keyInfo = ReadPKCS12.read(new FileInputStream("files/test.p12"), password, alias);
byte[] contents = rinfo.getContent(new JceKeyTransEnvelopedRecipient(keyInfo.getPrivateKey()).setProvider("BC"));
FileOutputStream envfos = new FileOutputStream("Decrypted.txt");
envfos.write(contents);
envfos.close();
}
Aggregations