本文整理汇总了Java中org.bouncycastle.cms.RecipientId.setSerialNumber方法的典型用法代码示例。如果您正苦于以下问题:Java RecipientId.setSerialNumber方法的具体用法?Java RecipientId.setSerialNumber怎么用?Java RecipientId.setSerialNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.cms.RecipientId
的用法示例。
在下文中一共展示了RecipientId.setSerialNumber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decryptEnvelope
import org.bouncycastle.cms.RecipientId; //导入方法依赖的package包/类
/**
* Try to decrypt the provided envelope with the provided certificate
* and private key.
*/
public static MimeBodyPart decryptEnvelope(SMIMEEnveloped enveloped,
Key key, X509Certificate cert)
throws Exception
{
// look for our recipient identifier
RecipientId recId = new RecipientId();
recId.setSerialNumber(cert.getSerialNumber());
recId.setIssuer(cert.getIssuerX500Principal().getEncoded());
RecipientInformationStore recipients = enveloped.getRecipientInfos();
RecipientInformation recipient = recipients.get(recId);
// decryption step
if (recipient != null)
return SMIMEUtil.toMimeBodyPart(recipient.getContent(key, "BC"));
else
return null;
}
示例2: addDecryptionSettings
import org.bouncycastle.cms.RecipientId; //导入方法依赖的package包/类
private void addDecryptionSettings() throws Exception {
char[] smimePw = new String(decryptionKeystorePass).toCharArray();
Security.addProvider(new BouncyCastleProvider());
ks = KeyStore.getInstance(PKCS_KEYSTORE_TYPE, BOUNCY_CASTLE_PROVIDER);
InputStream decryptionStream = new URL(decryptionKeystore).openStream();
try {
ks.load(decryptionStream, smimePw);
} finally {
decryptionStream.close();
}
if ("".equals(decryptionKeyAlias)) {
Enumeration aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias = (String) aliases.nextElement();
if (ks.isKeyEntry(alias)) {
decryptionKeyAlias = alias;
}
}
if ("".equals(decryptionKeyAlias)) {
throw new Exception("Can't find a private key!");
}
}
//
// find the certificate for the private key and generate a
// suitable recipient identifier.
//
X509Certificate cert = (X509Certificate)ks.getCertificate(decryptionKeyAlias);
if (null == cert) {
throw new Exception("Can't find a key pair with alias \"" + decryptionKeyAlias +
"\" in the given keystore");
}
if (verifyCertificate) {
cert.checkValidity();
}
recId = new RecipientId();
recId.setSerialNumber(cert.getSerialNumber());
recId.setIssuer(cert.getIssuerX500Principal().getEncoded());
}