@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 testReadOnly() { GuardedString str = new GuardedString("foo".toCharArray()); assertFalse(str.isReadOnly()); str.makeReadOnly(); assertTrue(str.isReadOnly()); assertEquals(decryptToString(str), "foo"); try { str.appendChar('2'); fail("expected exception"); } catch (IllegalStateException e) { /* ignore */ } str = str.copy(); assertEquals(decryptToString(str), "foo"); str.appendChar('2'); assertEquals(decryptToString(str), "foo2"); }
str.dispose(); try { decryptToString(str); fail("expected exception"); } catch (IllegalStateException e) {