如何在Java中解密PKCS7 bouncycastle

时间:2019-07-02 10:00:56

标签: java bouncycastle

我有通过PKCS7非对称加密方法加密的消息。里面有xml

我尝试通过以下方式对此进行解密

public static byte[] decryptData(byte[] encryptedData, PrivateKey decryptionKey) throws CMSException {

    byte[] decryptedData = null;
    if (null != encryptedData && null != decryptionKey) {
        CMSEnvelopedData envelopedData = new CMSEnvelopedData(encryptedData);

        Collection<RecipientInformation> recipients = envelopedData.getRecipientInfos().getRecipients();
        KeyTransRecipientInformation recipientInfo = (KeyTransRecipientInformation) recipients.iterator().next();
        JceKeyTransRecipient recipient = new JceKeyTransEnvelopedRecipient(decryptionKey);

        return recipientInfo.getContent(recipient);
    }
    return decryptedData;
}

其错误格式错误的内容

CMSEnvelopedData envelopedData = new CMSEnvelopedData(encryptedData);

0 个答案:

没有答案