/** * 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); }
/** * 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); } }
/** * 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); }
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 } }
/** * 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 encryptBytes(byte[] bytes) { Encryptor encryptor = getEncryptor(); byte[] newBytes = encryptor.encrypt(bytes); SecurityUtil.clear(encryptedBytes); encryptedBytes = newBytes; base64SHA1Hash = SecurityUtil.computeBase64SHA1Hash(bytes); }
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 void encryptBytes(byte [] bytes) { Encryptor encryptor = getEncryptor(); byte [] newBytes = encryptor.encrypt(bytes); SecurityUtil.clear(_encryptedBytes); _encryptedBytes = newBytes; _base64SHA1Hash = SecurityUtil.computeBase64SHA1Hash(bytes); }
private void encryptBytes(byte[] bytes) { Encryptor encryptor = getEncryptor(); byte[] newBytes = encryptor.encrypt(bytes); SecurityUtil.clear(encryptedBytes); encryptedBytes = newBytes; base64SHA1Hash = SecurityUtil.computeBase64SHA1Hash(bytes); }
private void encryptBytes(byte[] bytes) { Encryptor encryptor = getEncryptor(); byte[] newBytes = encryptor.encrypt(bytes); SecurityUtil.clear(encryptedBytes); encryptedBytes = newBytes; base64SHA1Hash = SecurityUtil.computeBase64SHA1Hash(bytes); }
properties.put(PROP_KEY, SecurityUtil.computeBase64SHA1Hash(key.toCharArray())); IOUtil.storePropertiesFile(new File(propertiesFileName), properties); } else if (cmd.equalsIgnoreCase("-setDefaults")) {
properties.put(PROP_KEY, SecurityUtil.computeBase64SHA1Hash(key.toCharArray())); IOUtil.storePropertiesFile(new File(propertiesFileName), properties); } else if (cmd.equalsIgnoreCase("-setDefaults")) {
properties.put(PROP_KEY, SecurityUtil.computeBase64SHA1Hash(key.toCharArray())); IOUtil.storePropertiesFile(new File(propertiesFileName), properties); } else if (cmd.equalsIgnoreCase("-setDefaults")) {
@Test public void testBasics() { GuardedString str = new GuardedString("foo".toCharArray()); assertEquals(decryptToString(str), "foo"); str.appendChar('2'); assertEquals(decryptToString(str), "foo2"); assertFalse(str.verifyBase64SHA1Hash(SecurityUtil .computeBase64SHA1Hash("foo".toCharArray()))); assertTrue(str.verifyBase64SHA1Hash(SecurityUtil .computeBase64SHA1Hash("foo2".toCharArray()))); }
@Test public void testBasics() { GuardedByteArray bytes = new GuardedByteArray(new byte[] { 0x00, 0x01, 0x02 }); assertTrue(Arrays.equals(decryptToBytes(bytes), new byte[] { 0x00, 0x01, 0x02 })); assertTrue(Arrays.equals(new byte[] { 0x00, 0x01, 0x02 }, decryptToBytes(bytes))); bytes.appendByte((byte) 0x03); assertTrue(Arrays.equals(new byte[] { 0x00, 0x01, 0x02, 0x03 }, decryptToBytes(bytes))); assertFalse(bytes.verifyBase64SHA1Hash( SecurityUtil.computeBase64SHA1Hash(new byte[] { 0x00, 0x01, 0x02 }))); assertTrue(bytes.verifyBase64SHA1Hash( SecurityUtil.computeBase64SHA1Hash(new byte[] { 0x00, 0x01, 0x02, 0x03 }))); }