本文整理匯總了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);
}
}