use of com.microsoft.azure.keyvault.models.KeyVerifyResult in project azure-sdk-for-java by Azure.
the class KeyVaultClientImpl method verifyWithServiceResponseAsync.
/**
* Verifies a signature using a specified key.
*
* @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
* @param keyName The name of the key.
* @param keyVersion The version of the key.
* @param algorithm The signing/verification algorithm. For more information on possible algorithm types, see JsonWebKeySignatureAlgorithm. Possible values include: 'RS256', 'RS384', 'RS512', 'RSNULL'
* @param digest The digest used for signing.
* @param signature The signature to be verified.
* @return the observable to the KeyVerifyResult object
*/
public Observable<ServiceResponse<KeyVerifyResult>> verifyWithServiceResponseAsync(String vaultBaseUrl, String keyName, String keyVersion, JsonWebKeySignatureAlgorithm algorithm, byte[] digest, byte[] signature) {
if (vaultBaseUrl == null) {
throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
}
if (keyName == null) {
throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
}
if (keyVersion == null) {
throw new IllegalArgumentException("Parameter keyVersion is required and cannot be null.");
}
if (this.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
}
if (algorithm == null) {
throw new IllegalArgumentException("Parameter algorithm is required and cannot be null.");
}
if (digest == null) {
throw new IllegalArgumentException("Parameter digest is required and cannot be null.");
}
if (signature == null) {
throw new IllegalArgumentException("Parameter signature is required and cannot be null.");
}
KeyVerifyParameters parameters = new KeyVerifyParameters();
parameters.withAlgorithm(algorithm);
parameters.withDigest(digest);
parameters.withSignature(signature);
String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
return service.verify(keyName, keyVersion, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<KeyVerifyResult>>>() {
@Override
public Observable<ServiceResponse<KeyVerifyResult>> call(Response<ResponseBody> response) {
try {
ServiceResponse<KeyVerifyResult> clientResponse = verifyDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
use of com.microsoft.azure.keyvault.models.KeyVerifyResult in project azure-sdk-for-java by Azure.
the class AsyncOperationsTest method keyAsync.
@Test
public void keyAsync() throws Exception {
String vault = getVaultUri();
String keyname = "mykey";
CreateKeyRequest createKeyRequest = new CreateKeyRequest.Builder(vault, keyname, JsonWebKeyType.RSA).build();
KeyBundle keyBundle = keyVaultClient.createKeyAsync(createKeyRequest, null).get();
Assert.assertNotNull(keyBundle);
UpdateKeyRequest updateKeyRequest = new UpdateKeyRequest.Builder(keyBundle.key().kid()).build();
keyBundle = keyVaultClient.updateKeyAsync(updateKeyRequest, null).get();
Assert.assertNotNull(keyBundle);
keyBundle = keyVaultClient.getKeyAsync(keyBundle.key().kid(), null).get();
Assert.assertNotNull(keyBundle);
List<KeyItem> keyItems = keyVaultClient.listKeysAsync(vault, 2, null).get();
Assert.assertNotNull(keyItems);
List<KeyItem> keyVersionItems = keyVaultClient.listKeyVersionsAsync(getVaultUri(), keyname, 2, null).get();
Assert.assertNotNull(keyVersionItems);
BackupKeyResult backupResult = keyVaultClient.backupKeyAsync(vault, keyname, null).get();
Assert.assertNotNull(backupResult);
keyVaultClient.deleteKeyAsync(keyBundle.keyIdentifier().vault(), keyBundle.keyIdentifier().name(), null).get();
KeyBundle restoreResult = keyVaultClient.restoreKeyAsync(vault, backupResult.value(), null).get();
Assert.assertNotNull(restoreResult);
KeyOperationResult encryptResult = keyVaultClient.encryptAsync(keyBundle.key().kid(), JsonWebKeyEncryptionAlgorithm.RSA_OAEP, new byte[100], null).get();
Assert.assertNotNull(encryptResult);
KeyOperationResult decryptResult = keyVaultClient.decryptAsync(keyBundle.key().kid(), JsonWebKeyEncryptionAlgorithm.RSA_OAEP, encryptResult.result(), null).get();
Assert.assertNotNull(decryptResult);
KeyOperationResult wrapResult = keyVaultClient.wrapKeyAsync(keyBundle.key().kid(), JsonWebKeyEncryptionAlgorithm.RSA_OAEP, new byte[100], null).get();
Assert.assertNotNull(wrapResult);
KeyOperationResult unwrapResult = keyVaultClient.unwrapKeyAsync(keyBundle.key().kid(), JsonWebKeyEncryptionAlgorithm.RSA_OAEP, wrapResult.result(), null).get();
Assert.assertNotNull(unwrapResult);
byte[] plainText = new byte[100];
new Random(0x1234567L).nextBytes(plainText);
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(plainText);
byte[] digest = md.digest();
KeyOperationResult signResult = keyVaultClient.signAsync(keyBundle.key().kid(), JsonWebKeySignatureAlgorithm.RS256, digest, null).get();
Assert.assertNotNull(signResult);
KeyVerifyResult verifypResult = keyVaultClient.verifyAsync(keyBundle.key().kid(), JsonWebKeySignatureAlgorithm.RS256, digest, signResult.result(), null).get();
Assert.assertTrue(verifypResult.value());
keyBundle = keyVaultClient.deleteKeyAsync(keyBundle.keyIdentifier().vault(), keyBundle.keyIdentifier().name(), null).get();
Assert.assertNotNull(keyBundle);
try {
keyVaultClient.deleteKeyAsync(keyBundle.keyIdentifier().vault(), keyBundle.keyIdentifier().name(), null).get();
} catch (ExecutionException ex) {
Throwable t = ex.getCause();
if (t instanceof KeyVaultErrorException) {
Assert.assertEquals("KeyNotFound", ((KeyVaultErrorException) t).body().error().code());
} else
throw ex;
}
}
use of com.microsoft.azure.keyvault.models.KeyVerifyResult in project azure-sdk-for-java by Azure.
the class KeyOperationsTest method signVerifyOperations.
@Test
public void signVerifyOperations() throws Exception {
JsonWebKey testKey = importTestKey();
KeyIdentifier keyId = new KeyIdentifier(testKey.kid());
// Test variables
byte[] plainText = new byte[100];
new Random(0x1234567L).nextBytes(plainText);
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(plainText);
byte[] digest = md.digest();
byte[] signature;
KeyOperationResult result;
KeyVerifyResult verifyResult;
// Using kid WO version
{
result = keyVaultClient.sign(keyId.baseIdentifier(), JsonWebKeySignatureAlgorithm.RS256, digest);
signature = result.result();
verifyResult = keyVaultClient.verify(keyId.baseIdentifier(), JsonWebKeySignatureAlgorithm.RS256, digest, signature);
Assert.assertEquals(new Boolean(true), verifyResult.value());
}
// Using full kid
{
result = keyVaultClient.sign(testKey.kid(), JsonWebKeySignatureAlgorithm.RS256, digest);
signature = result.result();
verifyResult = keyVaultClient.verify(testKey.kid(), JsonWebKeySignatureAlgorithm.RS256, digest, signature);
Assert.assertEquals(new Boolean(true), verifyResult.value());
}
}
Aggregations