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


Java KeyGenerator.getProvider方法代碼示例

本文整理匯總了Java中javax.crypto.KeyGenerator.getProvider方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyGenerator.getProvider方法的具體用法?Java KeyGenerator.getProvider怎麽用?Java KeyGenerator.getProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.crypto.KeyGenerator的用法示例。


在下文中一共展示了KeyGenerator.getProvider方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generate

import javax.crypto.KeyGenerator; //導入方法依賴的package包/類
/**
 * generate an authenticated object that contains an CMS Authenticated Data
 * object using the given provider and the passed in key generator.
 * @deprecated
 */
private CMSAuthenticatedData generate(
    final CMSProcessable  content,
    String          macOID,
    KeyGenerator    keyGen,
    Provider        provider)
    throws NoSuchAlgorithmException, CMSException
{
    Provider                encProvider = keyGen.getProvider();

    convertOldRecipients(rand, provider);

    return generate(new CMSTypedData()
    {
        public ASN1ObjectIdentifier getContentType()
        {
            return CMSObjectIdentifiers.data;
        }

        public void write(OutputStream out)
            throws IOException, CMSException
        {
            content.write(out);
        }

        public Object getContent()
        {
            return content;
        }
    }, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(macOID)).setProvider(encProvider).setSecureRandom(rand).build());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:36,代碼來源:CMSAuthenticatedDataGenerator.java

示例2: generateCEK

import javax.crypto.KeyGenerator; //導入方法依賴的package包/類
/**
 * @param kekMaterials non-null encryption materials
 */
protected final SecretKey generateCEK(
        final EncryptionMaterials kekMaterials,
        final Provider providerIn) {
    final String keygenAlgo = contentCryptoScheme.getKeyGeneratorAlgorithm();
    KeyGenerator generator;
    try {
        generator = providerIn == null
            ? KeyGenerator.getInstance(keygenAlgo)
            : KeyGenerator.getInstance(keygenAlgo, providerIn);
        generator.init(contentCryptoScheme.getKeyLengthInBits(),
                cryptoScheme.getSecureRandom());
        // Set to true iff the key encryption involves the use of BC's public key
        boolean involvesBCPublicKey = false;
        KeyPair keypair = kekMaterials.getKeyPair();
        if (keypair != null) {
            String keyWrapAlgo = cryptoScheme.getKeyWrapScheme().getKeyWrapAlgorithm(keypair.getPublic());
            if (keyWrapAlgo == null) {
                Provider provider = generator.getProvider();
                String providerName = provider == null ? null : provider.getName();
                involvesBCPublicKey = CryptoRuntime.BOUNCY_CASTLE_PROVIDER.equals(providerName);
            }
        }
        SecretKey secretKey = generator.generateKey();
        if (!involvesBCPublicKey || secretKey.getEncoded()[0] != 0)
            return secretKey;
        for (int retry = 0; retry < 9; retry++) {
            // Regenerate the random key due to a bug/feature in BC:
            // https://github.com/aws/aws-sdk-android/issues/15
            secretKey = generator.generateKey();
            if (secretKey.getEncoded()[0] != 0)
                return secretKey;
        }
        // The probability of getting here is 2^80, which is impossible in practice.
        throw new SdkClientException("Failed to generate secret key");
    } catch (NoSuchAlgorithmException e) {
        throw new SdkClientException(
                "Unable to generate envelope symmetric key:"
                        + e.getMessage(), e);
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:44,代碼來源:S3CryptoModuleBase.java


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