List of usage examples for java.security NoSuchAlgorithmException NoSuchAlgorithmException
public NoSuchAlgorithmException(Throwable cause)
From source file:com.microsoft.azure.keyvault.extensions.SymmetricKey.java
@Override public Future<Triple<byte[], byte[], String>> encryptAsync(final byte[] plaintext, final byte[] iv, final byte[] authenticationData, final String algorithm) throws NoSuchAlgorithmException { if (plaintext == null) { throw new IllegalArgumentException("plaintext"); }//from w w w.j a va 2 s .c o m if (iv == null) { throw new IllegalArgumentException("iv"); } // Interpret the algorithm String algorithmName = (Strings.isNullOrWhiteSpace(algorithm)) ? getDefaultEncryptionAlgorithm() : algorithm; Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithmName); if (baseAlgorithm == null || !(baseAlgorithm instanceof SymmetricEncryptionAlgorithm)) { throw new NoSuchAlgorithmException(algorithm); } SymmetricEncryptionAlgorithm algo = (SymmetricEncryptionAlgorithm) baseAlgorithm; ICryptoTransform transform = null; try { transform = algo.CreateEncryptor(_key, iv, authenticationData); } catch (Exception e) { return new FutureExecutionException<Triple<byte[], byte[], String>>(e); } byte[] cipherText = null; try { cipherText = transform.doFinal(plaintext); } catch (Exception e) { return new FutureExecutionException<Triple<byte[], byte[], String>>(e); } byte[] authenticationTag = null; if (transform instanceof IAuthenticatedCryptoTransform) { IAuthenticatedCryptoTransform authenticatedTransform = (IAuthenticatedCryptoTransform) transform; authenticationTag = authenticatedTransform.getTag().clone(); } return new FutureImmediate<Triple<byte[], byte[], String>>( Triple.of(cipherText, authenticationTag, algorithm)); }
From source file:ee.ria.xroad.common.util.CryptoUtils.java
/** * Returns the digest/signature algorithm URI for the given digest/signature algorithm identifier. * @param algoId the id of the algorithm * @return the URI of the algorithm/* ww w . j a v a 2 s . c o m*/ * @throws NoSuchAlgorithmException if the algorithm id is unknown */ public static String getDigestAlgorithmURI(String algoId) throws NoSuchAlgorithmException { switch (algoId) { case SHA1_ID: return DigestMethod.SHA1; case SHA224_ID: return MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA224; case SHA256_ID: return DigestMethod.SHA256; case SHA384_ID: return MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA384; case SHA512_ID: return DigestMethod.SHA512; default: throw new NoSuchAlgorithmException("Unknown algorithm id: " + algoId); } }
From source file:com.microsoft.azure.keyvault.cryptography.RsaKey.java
@Override public ListenableFuture<Pair<byte[], String>> signAsync(final byte[] digest, final String algorithm) throws NoSuchAlgorithmException { if (digest == null) { throw new IllegalArgumentException("encryptedKey "); }// w ww .j a va 2 s.c om // Interpret the requested algorithm if (Strings.isNullOrWhiteSpace(algorithm)) { throw new IllegalArgumentException("algorithm"); } // Interpret the requested algorithm Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithm); if (baseAlgorithm == null || !(baseAlgorithm instanceof AsymmetricSignatureAlgorithm)) { throw new NoSuchAlgorithmException(algorithm); } Rs256 algo = (Rs256) baseAlgorithm; ISignatureTransform signer = algo.createSignatureTransform(_keyPair); try { return Futures.immediateFuture(Pair.of(signer.sign(digest), Rs256.ALGORITHM_NAME)); } catch (Exception e) { return Futures.immediateFailedFuture(e); } }
From source file:com.microsoft.azure.keyvault.extensions.RsaKey.java
@Override public Future<Triple<byte[], byte[], String>> encryptAsync(final byte[] plaintext, final byte[] iv, final byte[] authenticationData, final String algorithm) throws NoSuchAlgorithmException { if (plaintext == null) { throw new IllegalArgumentException("plaintext"); }/*from w w w. j av a 2 s .co m*/ // Interpret the requested algorithm String algorithmName = (Strings.isNullOrWhiteSpace(algorithm) ? getDefaultEncryptionAlgorithm() : algorithm); Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithmName); if (baseAlgorithm == null || !(baseAlgorithm instanceof AsymmetricEncryptionAlgorithm)) { throw new NoSuchAlgorithmException(algorithmName); } AsymmetricEncryptionAlgorithm algo = (AsymmetricEncryptionAlgorithm) baseAlgorithm; ICryptoTransform transform; Future<Triple<byte[], byte[], String>> result; try { transform = algo.CreateEncryptor(_keyPair); result = new FutureEncrypt(algorithmName, plaintext, transform); } catch (Exception e) { result = new FutureExecutionException<Triple<byte[], byte[], String>>(e); } return result; }
From source file:com.microsoft.azure.keyvault.cryptography.SymmetricKey.java
@Override public ListenableFuture<Triple<byte[], byte[], String>> encryptAsync(final byte[] plaintext, final byte[] iv, final byte[] authenticationData, final String algorithm) throws NoSuchAlgorithmException { if (plaintext == null) { throw new IllegalArgumentException("plaintext"); }//w w w . j a v a 2 s .c o m if (iv == null) { throw new IllegalArgumentException("iv"); } // Interpret the algorithm String algorithmName = (Strings.isNullOrWhiteSpace(algorithm)) ? getDefaultEncryptionAlgorithm() : algorithm; Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithmName); if (baseAlgorithm == null || !(baseAlgorithm instanceof SymmetricEncryptionAlgorithm)) { throw new NoSuchAlgorithmException(algorithm); } SymmetricEncryptionAlgorithm algo = (SymmetricEncryptionAlgorithm) baseAlgorithm; ICryptoTransform transform = null; try { transform = algo.CreateEncryptor(_key, iv, authenticationData, _provider); } catch (Exception e) { return Futures.immediateFailedFuture(e); } byte[] cipherText = null; try { cipherText = transform.doFinal(plaintext); } catch (Exception e) { return Futures.immediateFailedFuture(e); } byte[] authenticationTag = null; if (transform instanceof IAuthenticatedCryptoTransform) { IAuthenticatedCryptoTransform authenticatedTransform = (IAuthenticatedCryptoTransform) transform; authenticationTag = authenticatedTransform.getTag().clone(); } return Futures.immediateFuture(Triple.of(cipherText, authenticationTag, algorithm)); }
From source file:ee.ria.xroad.common.util.CryptoUtils.java
/** * Returns the digest/signature algorithm URI for the given digest/signature algorithm identifier. * @param algoId the id of the algorithm * @return the URI of the algorithm// www . j a v a2s . c o m * @throws NoSuchAlgorithmException if the algorithm id is unknown */ public static String getSignatureAlgorithmURI(String algoId) throws NoSuchAlgorithmException { switch (algoId) { case SHA1WITHRSA_ID: return ALGO_ID_SIGNATURE_RSA_SHA1; case SHA256WITHRSA_ID: return ALGO_ID_SIGNATURE_RSA_SHA256; case SHA384WITHRSA_ID: return ALGO_ID_SIGNATURE_RSA_SHA384; case SHA512WITHRSA_ID: return ALGO_ID_SIGNATURE_RSA_SHA512; case SHA256WITHRSAANDMGF1_ID: return ALGO_ID_SIGNATURE_RSA_SHA256_MGF1; case SHA384WITHRSAANDMGF1_ID: return ALGO_ID_SIGNATURE_RSA_SHA384_MGF1; case SHA512WITHRSAANDMGF1_ID: return ALGO_ID_SIGNATURE_RSA_SHA512_MGF1; default: throw new NoSuchAlgorithmException("Unknown algorithm id: " + algoId); } }
From source file:com.salesmanager.core.service.common.impl.EasySSLProtocolSocketFactory.java
public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException { super();/*from w w w . j a v a 2s.c o m*/ TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509"); factory.init(keystore); TrustManager[] trustmanagers = factory.getTrustManagers(); if (trustmanagers.length == 0) { throw new NoSuchAlgorithmException("SunX509 trust manager not supported"); } this.standardTrustManager = (X509TrustManager) trustmanagers[0]; }
From source file:com.microsoft.azure.keyvault.extensions.SymmetricKey.java
@Override public Future<Pair<byte[], String>> wrapKeyAsync(final byte[] key, final String algorithm) throws NoSuchAlgorithmException { if (key == null || key.length == 0) { throw new IllegalArgumentException("key"); }//from w ww . j a v a 2 s .c om // Interpret the algorithm String algorithmName = (Strings.isNullOrWhiteSpace(algorithm)) ? getDefaultKeyWrapAlgorithm() : algorithm; Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithmName); if (baseAlgorithm == null || !(baseAlgorithm instanceof KeyWrapAlgorithm)) { throw new NoSuchAlgorithmException(algorithmName); } KeyWrapAlgorithm algo = (KeyWrapAlgorithm) baseAlgorithm; ICryptoTransform transform = null; try { transform = algo.CreateEncryptor(_key, null, _provider); } catch (Exception e) { return new FutureExecutionException<Pair<byte[], String>>(e); } byte[] encrypted = null; try { encrypted = transform.doFinal(key); } catch (Exception e) { return new FutureExecutionException<Pair<byte[], String>>(e); } return new FutureImmediate<Pair<byte[], String>>(Pair.of(encrypted, algorithmName)); }
From source file:com.microsoft.azure.keyvault.cryptography.RsaKey.java
@Override public ListenableFuture<Boolean> verifyAsync(final byte[] digest, final byte[] signature, final String algorithm) throws NoSuchAlgorithmException { if (digest == null) { throw new IllegalArgumentException("encryptedKey "); }// w w w .j av a2 s . co m // Interpret the requested algorithm if (Strings.isNullOrWhiteSpace(algorithm)) { throw new IllegalArgumentException("algorithm"); } // Interpret the requested algorithm Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithm); if (baseAlgorithm == null || !(baseAlgorithm instanceof AsymmetricSignatureAlgorithm)) { throw new NoSuchAlgorithmException(algorithm); } Rs256 algo = (Rs256) baseAlgorithm; ISignatureTransform signer = algo.createSignatureTransform(_keyPair); try { return Futures.immediateFuture(signer.verify(digest, signature)); } catch (Exception e) { return Futures.immediateFailedFuture(e); } }
From source file:com.microsoft.azure.keyvault.extensions.RsaKey.java
@Override public Future<Pair<byte[], String>> wrapKeyAsync(final byte[] key, final String algorithm) throws NoSuchAlgorithmException { if (key == null) { throw new IllegalArgumentException("key"); }// ww w . ja v a2 s . com // Interpret the requested algorithm String algorithmName = (Strings.isNullOrWhiteSpace(algorithm) ? getDefaultKeyWrapAlgorithm() : algorithm); Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithmName); if (baseAlgorithm == null || !(baseAlgorithm instanceof AsymmetricEncryptionAlgorithm)) { throw new NoSuchAlgorithmException(algorithmName); } AsymmetricEncryptionAlgorithm algo = (AsymmetricEncryptionAlgorithm) baseAlgorithm; ICryptoTransform transform; Future<Pair<byte[], String>> result; try { transform = algo.CreateEncryptor(_keyPair); result = new FutureWrap(algorithmName, key, transform); } catch (Exception e) { result = new FutureExecutionException<Pair<byte[], String>>(e); } return result; }