/** * Create a copy of the byte array. If this instance is read-only, * the copy will not be read-only. * @return A copy of the byte array. * @throws IllegalStateException If the byte array has been disposed */ public GuardedByteArray copy() { checkNotDisposed(); byte [] encryptedBytes2 = new byte[_encryptedBytes.length]; System.arraycopy(_encryptedBytes, 0, encryptedBytes2, 0, _encryptedBytes.length); GuardedByteArray rv = new GuardedByteArray(); rv._encryptedBytes = encryptedBytes2; return rv; }
/** * Create a copy of the byte array. * * If this instance is read-only, the copy will not be read-only. * * @return A copy of the byte array. * @throws IllegalStateException * If the byte array has been disposed */ public GuardedByteArray copy() { checkNotDisposed(); byte[] encryptedBytes2 = new byte[encryptedBytes.length]; System.arraycopy(encryptedBytes, 0, encryptedBytes2, 0, encryptedBytes.length); GuardedByteArray rv = new GuardedByteArray(); rv.encryptedBytes = encryptedBytes2; return rv; }
/** * Create a copy of the byte array. * * If this instance is read-only, the copy will not be read-only. * * @return A copy of the byte array. * @throws IllegalStateException * If the byte array has been disposed */ public GuardedByteArray copy() { checkNotDisposed(); byte[] encryptedBytes2 = new byte[encryptedBytes.length]; System.arraycopy(encryptedBytes, 0, encryptedBytes2, 0, encryptedBytes.length); GuardedByteArray rv = new GuardedByteArray(); rv.encryptedBytes = encryptedBytes2; return rv; }
value = new GuardedString(values.get(0).toString().toCharArray()); } else if (GuardedByteArray.class.equals(propertySchemaClass)) { value = new GuardedByteArray((byte[]) values.get(0)); } else if (Character.class.equals(propertySchemaClass) || Character.TYPE.equals(propertySchemaClass)) { value = values.get(0) == null || values.get(0).toString().isEmpty()
@Override public Object deserialize(final ObjectDecoder decoder) { byte[] encryptedBytes = null; byte[] clearBytes = null; try { encryptedBytes = decoder.readByteArrayContents(); clearBytes = EncryptorFactory.getInstance().getDefaultEncryptor().decrypt(encryptedBytes); return new GuardedByteArray(clearBytes); } finally { SecurityUtil.clear(encryptedBytes); SecurityUtil.clear(clearBytes); } }
@Override public Object deserialize(final ObjectDecoder decoder) { byte[] encryptedBytes = null; byte[] clearBytes = null; try { encryptedBytes = decoder.readByteArrayContents(); clearBytes = EncryptorFactory.getInstance().getDefaultEncryptor().decrypt(encryptedBytes); return new GuardedByteArray(clearBytes); } finally { SecurityUtil.clear(encryptedBytes); SecurityUtil.clear(clearBytes); } }
@Override public Object deserialize(final ObjectDecoder decoder) { byte[] encryptedBytes = null; byte[] clearBytes = null; try { encryptedBytes = decoder.readByteArrayContents(); clearBytes = EncryptorFactory.getInstance().getDefaultEncryptor().decrypt(encryptedBytes); return new GuardedByteArray(clearBytes); } finally { SecurityUtil.clear(encryptedBytes); SecurityUtil.clear(clearBytes); } }
@Test public void testRange() { for (int i = -128; i < 128; i++) { final byte expected = (byte) i; GuardedByteArray bytes = new GuardedByteArray(new byte[] { (byte) i }); bytes.access((byte[] clearBytes) -> { byte v = clearBytes[0]; assertEquals(v, expected); }); } }
return new GuardedByteArray(((ProtectedByteArrayType) pval.getValue()).getClearBytes()); } else if (midPointRealValue instanceof PolyString) { return ((PolyString)midPointRealValue).getOrig();
@Test public void testEquals() { GuardedByteArray bytes1 = new GuardedByteArray(); GuardedByteArray bytes2 = new GuardedByteArray(); assertEquals(bytes1, bytes2); bytes2.appendByte((byte) 0x03); assertFalse(bytes1.equals(bytes2)); bytes1.appendByte((byte) 0x03); assertEquals(bytes1, bytes2); }
@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 }))); }
@Test public void testReadOnly() { GuardedByteArray bytes = new GuardedByteArray(new byte[] { 0x00, 0x01, 0x02 }); assertFalse(bytes.isReadOnly()); bytes.makeReadOnly(); assertTrue(bytes.isReadOnly()); assertTrue(Arrays.equals(new byte[] { 0x00, 0x01, 0x02 }, decryptToBytes(bytes))); try { bytes.appendByte((byte) 0x03); fail("expected exception"); } catch (IllegalStateException e) { /* ignore */ } bytes = bytes.copy(); 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))); }
@Test public void testDispose() { GuardedByteArray str = new GuardedByteArray(new byte[] { 0x00, 0x01, 0x02 }); str.dispose(); try {