@Override public final void destroy() throws DestroyFailedException { secretKey.destroy(); this.destroyed = true; } }
@Override public final void destroy() throws DestroyFailedException { secretKey.destroy(); this.destroyed = true; } }
public void clean() { if (ivp != null) { Arrays.fill(ivp, (byte) 0); } // Clean the key after we're done with it try { key.destroy(); } catch (DestroyFailedException e) { // ignore } } }
public void clean() { if (ivp != null) { Arrays.fill(ivp, (byte) 0); } // Clean the key after we're done with it try { key.destroy(); } catch (DestroyFailedException e) { // ignore } } }
public static byte[] generateKey() { SecretKey key = null; try { KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM); keyGenerator.init(256); key = keyGenerator.generateKey(); return key.getEncoded(); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } finally { if (key != null) { try { key.destroy(); } catch (DestroyFailedException ex) { } } } }
public static byte[] generateKey() { SecretKey key = null; try { KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM); keyGenerator.init(256); key = keyGenerator.generateKey(); return key.getEncoded(); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } finally { if (key != null) { try { key.destroy(); } catch (DestroyFailedException ex) { } } } }
public static String generateKey(String algo) { try { KeyGenerator keyGen = KeyGenerator.getInstance(algo); SecretKey secretKey = keyGen.generateKey(); byte[] encodedSecretKey = secretKey.getEncoded(); String encodedKey = Base64Utility.encode(encodedSecretKey); // Clean the key after we're done with it Arrays.fill(encodedSecretKey, (byte) 0); try { secretKey.destroy(); } catch (DestroyFailedException e) { // ignore } return encodedKey; } catch (NoSuchAlgorithmException e) { throw new SecurityException(e); } }
public static String generateKey(String algo) { try { KeyGenerator keyGen = KeyGenerator.getInstance(algo); SecretKey secretKey = keyGen.generateKey(); byte[] encodedSecretKey = secretKey.getEncoded(); String encodedKey = Base64Utility.encode(encodedSecretKey); // Clean the key after we're done with it Arrays.fill(encodedSecretKey, (byte) 0); try { secretKey.destroy(); } catch (DestroyFailedException e) { // ignore } return encodedKey; } catch (NoSuchAlgorithmException e) { throw new SecurityException(e); } }
public static Client decryptClient(String encodedSequence, String encodedSecretKey, KeyProperties props) throws SecurityException { SecretKey key = CryptoUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo()); Client client = decryptClient(encodedSequence, key, props); // Clean the secret key from memory when we're done try { key.destroy(); } catch (DestroyFailedException ex) { // ignore } return client; }
public static Client decryptClient(String encodedSequence, String encodedSecretKey, KeyProperties props) throws SecurityException { SecretKey key = CryptoUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo()); Client client = decryptClient(encodedSequence, key, props); // Clean the secret key from memory when we're done try { key.destroy(); } catch (DestroyFailedException ex) { // ignore } return client; }
protected byte[] encryptInternal(JweEncryptionInternal state, byte[] content) { try { SecretKey createCekSecretKey = createCekSecretKey(state); byte[] encryptedBytes = CryptoUtils.encryptBytes(content, createCekSecretKey, state.keyProps); // Here we're finished with the SecretKey we created, so we can destroy it try { createCekSecretKey.destroy(); } catch (DestroyFailedException e) { // ignore } return encryptedBytes; } catch (SecurityException ex) { LOG.fine(ex.getMessage()); if (ex.getCause() instanceof NoSuchAlgorithmException) { LOG.warning("Unsupported algorithm: " + state.keyProps.getKeyAlgo()); throw new JweException(JweException.Error.INVALID_CONTENT_ALGORITHM); } throw new JweException(JweException.Error.CONTENT_ENCRYPTION_FAILURE, ex); } } protected byte[] getActualCipher(byte[] cipher) {
protected byte[] decryptPayload(Element root, byte[] secretKeyBytes, String symEncAlgo) throws WSSecurityException { SecretKey key = KeyUtils.prepareSecretKey(symEncAlgo, secretKeyBytes); try { XMLCipher xmlCipher = EncryptionUtils.initXMLCipher(symEncAlgo, XMLCipher.DECRYPT_MODE, key); byte[] decryptedContent = xmlCipher.decryptToByteArray(root); // Clean the private key from memory now that we're finished with it try { key.destroy(); } catch (DestroyFailedException ex) { // ignore } return decryptedContent; } catch (XMLEncryptionException ex) { throw new WSSecurityException(WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, ex); } }
public byte[] getContentEncryptionKey(JweHeaders headers) { byte[] theCek = null; if (cek == null) { String algoJava = getAlgorithm().getJavaName(); SecretKey secretKey = CryptoUtils.getSecretKey(AlgorithmUtils.stripAlgoProperties(algoJava), getContentEncryptionKeySize(headers)); theCek = secretKey.getEncoded(); if (generateCekOnce) { synchronized (this) { cek = theCek; } } // Clean the key after we're done with it try { secretKey.destroy(); } catch (DestroyFailedException e) { // ignore } } else { theCek = cek; } return theCek; } public byte[] getInitVector() {
public static RefreshToken decryptRefreshToken(OAuthDataProvider provider, String encodedToken, String encodedSecretKey, KeyProperties props) throws SecurityException { SecretKey key = CryptoUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo()); RefreshToken refreshToken = decryptRefreshToken(provider, encodedToken, key, props); // Clean the secret key from memory when we're done try { key.destroy(); } catch (DestroyFailedException ex) { // ignore } return refreshToken; }
public static ServerAccessToken decryptAccessToken(OAuthDataProvider provider, String encodedToken, String encodedSecretKey, KeyProperties props) throws SecurityException { SecretKey key = CryptoUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo()); ServerAccessToken serverAccessToken = decryptAccessToken(provider, encodedToken, key, props); // Clean the secret key from memory when we're done try { key.destroy(); } catch (DestroyFailedException ex) { // ignore } return serverAccessToken; }
public static ServerAuthorizationCodeGrant decryptCodeGrant(OAuthDataProvider provider, String encodedToken, String encodedSecretKey, KeyProperties props) throws SecurityException { SecretKey key = CryptoUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo()); ServerAuthorizationCodeGrant authzCodeGrant = decryptCodeGrant(provider, encodedToken, key, props); // Clean the secret key from memory when we're done try { key.destroy(); } catch (DestroyFailedException ex) { // ignore } return authzCodeGrant; }
protected byte[] decryptPayload(Element root, byte[] secretKeyBytes, String symEncAlgo) throws WSSecurityException { SecretKey key = KeyUtils.prepareSecretKey(symEncAlgo, secretKeyBytes); try { XMLCipher xmlCipher = EncryptionUtils.initXMLCipher(symEncAlgo, XMLCipher.DECRYPT_MODE, key); byte[] decryptedContent = xmlCipher.decryptToByteArray(root); // Clean the private key from memory now that we're finished with it try { key.destroy(); } catch (DestroyFailedException ex) { // ignore } return decryptedContent; } catch (XMLEncryptionException ex) { throw new WSSecurityException(WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, ex); } }
public static ServerAccessToken decryptAccessToken(OAuthDataProvider provider, String encodedToken, String encodedSecretKey, KeyProperties props) throws SecurityException { SecretKey key = CryptoUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo()); ServerAccessToken serverAccessToken = decryptAccessToken(provider, encodedToken, key, props); // Clean the secret key from memory when we're done try { key.destroy(); } catch (DestroyFailedException ex) { // ignore } return serverAccessToken; }
public static RefreshToken decryptRefreshToken(OAuthDataProvider provider, String encodedToken, String encodedSecretKey, KeyProperties props) throws SecurityException { SecretKey key = CryptoUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo()); RefreshToken refreshToken = decryptRefreshToken(provider, encodedToken, key, props); // Clean the secret key from memory when we're done try { key.destroy(); } catch (DestroyFailedException ex) { // ignore } return refreshToken; }
public static ServerAuthorizationCodeGrant decryptCodeGrant(OAuthDataProvider provider, String encodedToken, String encodedSecretKey, KeyProperties props) throws SecurityException { SecretKey key = CryptoUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo()); ServerAuthorizationCodeGrant authzCodeGrant = decryptCodeGrant(provider, encodedToken, key, props); // Clean the secret key from memory when we're done try { key.destroy(); } catch (DestroyFailedException ex) { // ignore } return authzCodeGrant; }