當前位置: 首頁>>代碼示例>>Java>>正文


Java CMSEnvelopedDataGenerator類代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:daviszhou,項目名稱:BeaconTrackerAndroid,代碼行數:30,代碼來源:BridgeDataArchive.java

示例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);
    }
}
 
開發者ID:ResearchStack,項目名稱:MoleMapperAndroid,代碼行數:30,代碼來源:BridgeDataArchive.java


注:本文中的org.spongycastle.cms.CMSEnvelopedDataGenerator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。