本文整理汇总了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());
}
示例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);
}
}