当前位置: 首页>>代码示例>>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;未经允许,请勿转载。