/** * Provides access to the clear-text value of the byte array in a controlled fashion. * The clear-text bytes will only be available for the duration of the call * and automatically zeroed out following the call. * * <p> * <b>NOTE:</b> Callers are encouraged to use {@link #verifyBase64SHA1Hash(String)} * where possible if the intended use is merely to verify the contents of * the byte array match an expected hash value. * @param accessor Accessor callback. * @throws IllegalStateException If the byte array has been disposed */ public void access(Accessor accessor) { checkNotDisposed(); byte[] clearBytes = null; try { clearBytes = decryptBytes(); accessor.access(clearBytes); } finally { SecurityUtil.clear(clearBytes); } }
/** * Provides access to the clear-text value of the byte array in a controlled * fashion. * * The clear-text bytes will only be available for the duration of the call * and automatically zeroed out following the call. * <p> * <b>NOTE:</b> Callers are encouraged to use * {@link #verifyBase64SHA1Hash(String)} where possible if the intended use * is merely to verify the contents of the byte array match an expected hash * value. * * @param accessor * Accessor callback. * @throws IllegalStateException * If the byte array has been disposed */ public void access(Accessor accessor) { checkNotDisposed(); byte[] clearBytes = null; try { clearBytes = decryptBytes(); accessor.access(clearBytes); } finally { SecurityUtil.clear(clearBytes); } }
/** * Provides access to the clear-text value of the byte array in a controlled * fashion. * * The clear-text bytes will only be available for the duration of the call * and automatically zeroed out following the call. * <p> * <b>NOTE:</b> Callers are encouraged to use * {@link #verifyBase64SHA1Hash(String)} where possible if the intended use * is merely to verify the contents of the byte array match an expected hash * value. * * @param accessor * Accessor callback. * @throws IllegalStateException * If the byte array has been disposed */ public void access(Accessor accessor) { checkNotDisposed(); byte[] clearBytes = null; try { clearBytes = decryptBytes(); accessor.access(clearBytes); } finally { SecurityUtil.clear(clearBytes); } }
/** * Appends a single clear-text byte to the secure byte array. * The in-memory data will be decrypted, the byte will be * appended, and then it will be re-encrypted. * @param b The byte to append. * @throws IllegalStateException If the byte array is read-only * @throws IllegalStateException If the byte array has been disposed */ public void appendByte(byte b) { checkNotDisposed(); checkWriteable(); byte[] clearBytes = null; byte[] clearBytes2 = null; try { clearBytes = decryptBytes(); clearBytes2 = new byte[clearBytes.length+1]; System.arraycopy(clearBytes, 0, clearBytes2, 0, clearBytes.length); clearBytes2[clearBytes2.length-1] = b; encryptBytes(clearBytes2); } finally { SecurityUtil.clear(clearBytes); SecurityUtil.clear(clearBytes2); } }
/** * Appends a single clear-text byte to the secure byte array. * * The in-memory data will be decrypted, the byte will be appended, and then * it will be re-encrypted. * * @param b * The byte to append. * @throws IllegalStateException * If the byte array is read-only * @throws IllegalStateException * If the byte array has been disposed */ public void appendByte(byte b) { checkNotDisposed(); checkWriteable(); byte[] clearBytes = null; byte[] clearBytes2 = null; try { clearBytes = decryptBytes(); clearBytes2 = new byte[clearBytes.length + 1]; System.arraycopy(clearBytes, 0, clearBytes2, 0, clearBytes.length); clearBytes2[clearBytes2.length - 1] = b; encryptBytes(clearBytes2); } finally { SecurityUtil.clear(clearBytes); SecurityUtil.clear(clearBytes2); } }
/** * Appends a single clear-text byte to the secure byte array. * * The in-memory data will be decrypted, the byte will be appended, and then * it will be re-encrypted. * * @param b * The byte to append. * @throws IllegalStateException * If the byte array is read-only * @throws IllegalStateException * If the byte array has been disposed */ public void appendByte(byte b) { checkNotDisposed(); checkWriteable(); byte[] clearBytes = null; byte[] clearBytes2 = null; try { clearBytes = decryptBytes(); clearBytes2 = new byte[clearBytes.length + 1]; System.arraycopy(clearBytes, 0, clearBytes2, 0, clearBytes.length); clearBytes2[clearBytes2.length - 1] = b; encryptBytes(clearBytes2); } finally { SecurityUtil.clear(clearBytes); SecurityUtil.clear(clearBytes2); } }