本文整理汇总了Java中com.amazonaws.services.kms.AWSKMS.decrypt方法的典型用法代码示例。如果您正苦于以下问题:Java AWSKMS.decrypt方法的具体用法?Java AWSKMS.decrypt怎么用?Java AWSKMS.decrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.kms.AWSKMS
的用法示例。
在下文中一共展示了AWSKMS.decrypt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decrypt
import com.amazonaws.services.kms.AWSKMS; //导入方法依赖的package包/类
public static String decrypt(String str, Region region) throws UnsupportedEncodingException {
if (isJUnitTest()) {
return str;
}
AWSKMS kms = AWSKMSClientBuilder.standard().withRegion(region.getName()).build();
/*
* The KMS ciphertext is base64 encoded and must be decoded before the request is made
*/
String cipherString = str;
byte[] cipherBytes = Base64.decode(cipherString);
/*
* Create decode request and decode
*/
ByteBuffer cipherBuffer = ByteBuffer.wrap(cipherBytes);
DecryptRequest req = new DecryptRequest().withCiphertextBlob(cipherBuffer);
DecryptResult resp = kms.decrypt(req);
/*
* Convert the response plaintext bytes to a string
*/
return new String(resp.getPlaintext().array(), Charset.forName("UTF-8"));
}
示例2: decryptToken
import com.amazonaws.services.kms.AWSKMS; //导入方法依赖的package包/类
/**
* Decodes the encrypted token and attempts to decrypt it using AWS KMS. If
* successful, the token is returned.
*
* @param kmsClient KMS client
* @param encryptedToken Token to decode and decrypt
* @return Decrypted token
*/
protected VaultAuthResponse decryptToken(AWSKMS kmsClient, String encryptedToken) {
byte[] decodedToken;
try {
decodedToken = Base64.decode(encryptedToken);
} catch (IllegalArgumentException iae) {
throw new VaultClientException("Encrypted token not Base64 encoded", iae);
}
final DecryptRequest request = new DecryptRequest().withCiphertextBlob(ByteBuffer.wrap(decodedToken));
final DecryptResult result = kmsClient.decrypt(request);
final String decryptedAuthData = new String(result.getPlaintext().array(), Charset.forName("UTF-8"));
return gson.fromJson(decryptedAuthData, VaultAuthResponse.class);
}
示例3: cekByKMS
import com.amazonaws.services.kms.AWSKMS; //导入方法依赖的package包/类
/**
* Decrypts the secured CEK via KMS; involves network calls.
*
* @return the CEK (in plaintext).
*/
private static SecretKey cekByKMS(byte[] cekSecured, String keyWrapAlgo,
EncryptionMaterials materials,
ContentCryptoScheme contentCryptoScheme, AWSKMS kms) {
DecryptRequest kmsreq = new DecryptRequest()
.withEncryptionContext(materials.getMaterialsDescription())
.withCiphertextBlob(ByteBuffer.wrap(cekSecured));
DecryptResult result = kms.decrypt(kmsreq);
return new SecretKeySpec(copyAllBytesFrom(result.getPlaintext()),
contentCryptoScheme.getKeyGeneratorAlgorithm());
}