private void encryptBytes(byte[] bytes) { Encryptor encryptor = getEncryptor(); byte[] newBytes = encryptor.encrypt(bytes); SecurityUtil.clear(encryptedBytes); encryptedBytes = newBytes; base64SHA1Hash = SecurityUtil.computeBase64SHA1Hash(bytes); }
private char[] decryptChars() { byte[] clearBytes = null; try { clearBytes = decryptBytes(); return SecurityUtil.bytesToChars(clearBytes); } finally { SecurityUtil.clear(clearBytes); } }
/** * Computes the base 64 encoded SHA1 hash of the input. * * @param input The input chars * @return the hash */ public static String computeBase64SHA1Hash(char[] input) { // convert the char [] to bytes. I know there are utility methods for doing this, but I don't // know what sort of buffering they use. because it is possibly sensitive data, we do this in line so // that we can clear out our bytes after we are done. byte[] bytes = null; try { bytes = SecurityUtil.charsToBytes(input); return SecurityUtil.computeBase64SHA1Hash(bytes); } finally { // clear the possibly sensitive bytes out SecurityUtil.clear(bytes); // no need to clear "data" since it is now just a hash } }
private void encryptChars(char[] chars) { byte[] clearBytes = null; try { clearBytes = SecurityUtil.charsToBytes(chars); encryptBytes(clearBytes); } finally { SecurityUtil.clear(clearBytes); } }
/** * Clears the in-memory representation of the string. */ public void dispose() { SecurityUtil.clear(encryptedBytes); disposed = true; }
/** * Verifies the base 64-encoded SHA1 hash of the input. * * @param input The input chars * @param hash The expected hash * @return true if the hash of the input characters matches the expected * hash. */ public static boolean verifyBase64SHA1Hash(char[] input, String hash) { String inputHash = computeBase64SHA1Hash(input); return inputHash.equals(hash); }
/** * Extract password value from passed value (if instance of GuardedString or GuardedByteArray). * * @param pwd received from the underlying connector * @return password value */ public static String getPassword(final Object pwd) { final StringBuilder result = new StringBuilder(); if (pwd instanceof GuardedString) { result.append(SecurityUtil.decrypt((GuardedString) pwd)); } else if (pwd instanceof GuardedByteArray) { result.append(SecurityUtil.decrypt((GuardedByteArray) pwd)); } else if (pwd instanceof String) { result.append((String) pwd); } else { result.append(pwd.toString()); } return result.toString(); }
/** * Clears the in-memory representation of the byte array. */ public void dispose() { SecurityUtil.clear(encryptedBytes); disposed = true; }
private void encryptChars(char [] chars) { byte [] clearBytes = null; try { clearBytes = SecurityUtil.charsToBytes(chars); encryptBytes(clearBytes); } finally { SecurityUtil.clear(clearBytes); } }
/** * Verifies the base 64-encoded SHA1 hash of the input. * @param input The input chars * @param hash The expected hash * @return true if the hash of the input characters matches the expected hash. */ public static boolean verifyBase64SHA1Hash(char [] input, String hash) { String inputHash = computeBase64SHA1Hash(input); return inputHash.equals(hash); } }
EncryptorFactory.getInstance().getDefaultEncryptor().encrypt(SecurityUtil.decrypt(source).getBytes()); jgen.writeStringField("encryptedBytes", Base64.getEncoder().encodeToString(encryptedBytes));
private void encryptBytes(byte[] bytes) { Encryptor encryptor = getEncryptor(); byte[] newBytes = encryptor.encrypt(bytes); SecurityUtil.clear(encryptedBytes); encryptedBytes = newBytes; base64SHA1Hash = SecurityUtil.computeBase64SHA1Hash(bytes); }
/** * Computes the base 64 encoded SHA1 hash of the input. * * @param input The input chars * @return the hash */ public static String computeBase64SHA1Hash(char[] input) { // convert the char [] to bytes. I know there are utility methods for doing this, but I don't // know what sort of buffering they use. because it is possibly sensitive data, we do this in line so // that we can clear out our bytes after we are done. byte[] bytes = null; try { bytes = SecurityUtil.charsToBytes(input); return SecurityUtil.computeBase64SHA1Hash(bytes); } finally { // clear the possibly sensitive bytes out SecurityUtil.clear(bytes); // no need to clear "data" since it is now just a hash } }
private char [] decryptChars() { byte [] clearBytes = null; try { clearBytes = decryptBytes(); return SecurityUtil.bytesToChars(clearBytes); } finally { SecurityUtil.clear(clearBytes); } }
/** * Clears the in-memory representation of the string. */ public void dispose() { SecurityUtil.clear(_encryptedBytes); _disposed = true; }
private void encryptChars(char[] chars) { byte[] clearBytes = null; try { clearBytes = SecurityUtil.charsToBytes(chars); encryptBytes(clearBytes); } finally { SecurityUtil.clear(clearBytes); } }
/** * Verifies the base 64-encoded SHA1 hash of the input. * * @param input The input chars * @param hash The expected hash * @return true if the hash of the input characters matches the expected * hash. */ public static boolean verifyBase64SHA1Hash(char[] input, String hash) { String inputHash = computeBase64SHA1Hash(input); return inputHash.equals(hash); }
EncryptorFactory.getInstance().getDefaultEncryptor().encrypt(SecurityUtil.decrypt(source).getBytes()); jgen.writeStringField("encryptedBytes", Base64.getEncoder().encodeToString(encryptedBytes));
private void encryptBytes(byte [] bytes) { Encryptor encryptor = getEncryptor(); byte [] newBytes = encryptor.encrypt(bytes); SecurityUtil.clear(_encryptedBytes); _encryptedBytes = newBytes; _base64SHA1Hash = SecurityUtil.computeBase64SHA1Hash(bytes); }
/** * Computes the base 64 encoded SHA1 hash of the input * @param input The input chars * @return the hash */ public static String computeBase64SHA1Hash(char [] input) { //convert the char [] to bytes. I know there //are utility methods for doing this, but I don't //know what sort of buffering they use. because it //is possibly sensitive data, we do this in line so //that we can clear out our bytes after we are done. byte [] bytes = null; try { bytes = SecurityUtil.charsToBytes(input); return SecurityUtil.computeBase64SHA1Hash(bytes); } finally { //clear the possibly sensitive bytes out SecurityUtil.clear(bytes); //no need to clear "data" since it is now just a hash } }