本文整理匯總了Java中org.spongycastle.cms.CMSEnvelopedDataGenerator類的典型用法代碼示例。如果您正苦於以下問題:Java CMSEnvelopedDataGenerator類的具體用法?Java CMSEnvelopedDataGenerator怎麽用?Java CMSEnvelopedDataGenerator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CMSEnvelopedDataGenerator類屬於org.spongycastle.cms包,在下文中一共展示了CMSEnvelopedDataGenerator類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getEncryptedInputStream
import org.spongycastle.cms.CMSEnvelopedDataGenerator; //導入依賴的package包/類
@NonNull
private InputStream getEncryptedInputStream(Context context, File tempFile, ResourcePathManager.Resource publicKey)
{
// Creating a CMS encrypted input stream that only recipients can decrypt
CMSEnvelopedDataGenerator gen = new CMSEnvelopedDataGenerator();
// Load bridge public key certificate from R.raw and add to recipients list
try
{
CertificateFactory factory = new CertificateFactory();
InputStream keyInputStream = publicKey.open(context);
X509Certificate cert = (X509Certificate) factory.engineGenerateCertificate(
keyInputStream);
JceKeyTransRecipientInfoGenerator recipientInfoGenerator = new JceKeyTransRecipientInfoGenerator(
cert).setProvider("SC");
gen.addRecipientInfoGenerator(recipientInfoGenerator);
// Generate encrypted input stream in AES-256-CBC format, output is DER, not S/MIME or PEM
CMSProcessableFile content = new CMSProcessableFile(tempFile);
OutputEncryptor encryptor = new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES256_CBC).setProvider(
"SC").build();
CMSEnvelopedData envelopedData = gen.generate(content, encryptor);
return new BufferedInputStream(new ByteArrayInputStream(envelopedData.getEncoded()));
}
catch(CertificateException | IOException | CMSException e)
{
throw new RuntimeException("Error encrypting with CMS", e);
}
}
示例2: getEncryptedInputStream
import org.spongycastle.cms.CMSEnvelopedDataGenerator; //導入依賴的package包/類
@NonNull
private InputStream getEncryptedInputStream(Context context, File tempFile, ResourcePathManager.Resource publicKey)
{
// Creating a CMS encrypted input stream that only recipients can decrypt
CMSEnvelopedDataGenerator gen = new CMSEnvelopedDataGenerator();
// Load bridge public key certificate from R.raw and add to recipients list
try
{
CertificateFactory factory = new CertificateFactory();
InputStream keyInputStream = publicKey.open(context);
X509Certificate cert = (X509Certificate) factory.engineGenerateCertificate(
keyInputStream);
JceKeyTransRecipientInfoGenerator recipientInfoGenerator = new JceKeyTransRecipientInfoGenerator(
cert).setProvider("SC");
gen.addRecipientInfoGenerator(recipientInfoGenerator);
// Generate encrypted input stream in AES-256-CBC format, output is DER, not S/MIME or PEM
CMSProcessableFile content = new CMSProcessableFile(tempFile);
OutputEncryptor encryptor = new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES256_CBC).setProvider(
"SC").build();
CMSEnvelopedData envelopedData = gen.generate(content, encryptor);
return new BufferedInputStream(new ByteArrayInputStream(envelopedData.getEncoded()));
}
catch(CertificateException | IOException | CMSException e)
{
throw new RuntimeException("Error encrypting with CMS", e);
}
}