Search in sources :

Example 1 with KeyInformation

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();
}
Also used : CMSEnvelopedData(org.bouncycastle.cms.CMSEnvelopedData) FileOutputStream(java.io.FileOutputStream) KeyTransRecipientInformation(org.bouncycastle.cms.KeyTransRecipientInformation) JceKeyTransEnvelopedRecipient(org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient) FileInputStream(java.io.FileInputStream) KeyInformation(com.bluenimble.platform.crypto.tests.KeyInformation)

Aggregations

KeyInformation (com.bluenimble.platform.crypto.tests.KeyInformation)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 CMSEnvelopedData (org.bouncycastle.cms.CMSEnvelopedData)1 KeyTransRecipientInformation (org.bouncycastle.cms.KeyTransRecipientInformation)1 JceKeyTransEnvelopedRecipient (org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient)1