@Test(expected=BlobCrypterException.class) public void testTamperMac() throws Exception { Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); byte[] blobBytes = Base64.decodeBase64(blob.getBytes()); blobBytes[blobBytes.length-1] ^= 0x01; String tampered = new String(Base64.encodeBase64(blobBytes)); crypter.unwrap(tampered); }
@Test(expected=BlobCrypterException.class) public void testTamperMac() throws Exception { Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); byte[] blobBytes = Base64.decodeBase64(blob.getBytes()); blobBytes[blobBytes.length-1] ^= 0x01; String tampered = new String(Base64.encodeBase64(blobBytes)); crypter.unwrap(tampered); }
@Test(expected=BlobCrypterException.class) public void testTamperData() throws Exception { Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); byte[] blobBytes = Base64.decodeBase64(blob.getBytes()); blobBytes[30] ^= 0x01; String tampered = new String(Base64.encodeBase64(blobBytes)); crypter.unwrap(tampered); }
@Test(expected=BlobCrypterException.class) public void testTamperMac() throws Exception { Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); byte[] blobBytes = Base64.decodeBase64(blob.getBytes()); blobBytes[blobBytes.length-1] ^= 0x01; String tampered = new String(Base64.encodeBase64(blobBytes)); crypter.unwrap(tampered, 30); }
@Test(expected=BlobCrypterException.class) public void testTamperIV() throws Exception { Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); byte[] blobBytes = Base64.decodeBase64(blob.getBytes()); blobBytes[0] ^= 0x01; String tampered = new String(Base64.encodeBase64(blobBytes)); crypter.unwrap(tampered, 30); }
@Test(expected=BlobCrypterException.class) public void testTamperIV() throws Exception { Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); byte[] blobBytes = Base64.decodeBase64(blob.getBytes()); blobBytes[0] ^= 0x01; String tampered = new String(Base64.encodeBase64(blobBytes)); crypter.unwrap(tampered); }
@Test(expected=BlobCrypterException.class) public void testTamperIV() throws Exception { Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); byte[] blobBytes = Base64.decodeBase64(blob.getBytes()); blobBytes[0] ^= 0x01; String tampered = new String(Base64.encodeBase64(blobBytes)); crypter.unwrap(tampered); }
@Test(expected=BlobCrypterException.class) public void testTamperData() throws Exception { Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); byte[] blobBytes = Base64.decodeBase64(blob.getBytes()); blobBytes[30] ^= 0x01; String tampered = new String(Base64.encodeBase64(blobBytes)); crypter.unwrap(tampered); }
private void checkString(String string) throws Exception { Map<String, String> in = Maps.newHashMap(); if (string != null) { in.put("a", string); } String blob = crypter.wrap(in); Map<String, String> out = crypter.unwrap(blob); assertEquals(string, out.get("a")); }
private void checkString(String string) throws Exception { Map<String, String> in = Maps.newHashMap(); if (string != null) { in.put("a", string); } String blob = crypter.wrap(in); Map<String, String> out = crypter.unwrap(blob); assertEquals(string, out.get("a")); }
private void checkString(String string) throws Exception { Map<String, String> in = Maps.newHashMap(); if (string != null) { in.put("a", string); } String blob = crypter.wrap(in); Map<String, String> out = crypter.unwrap(blob, 0); assertEquals(string, out.get("a")); }
private void checkString(String string) throws Exception { Map<String, String> in = Maps.newHashMap(); if (string != null) { in.put("a", string); } String blob = crypter.wrap(in); Map<String, String> out = crypter.unwrap(blob, 0); assertEquals(string, out.get("a")); }
@Test public void testManyEntries() throws Exception { Map<String, String> in = Maps.newHashMap(); for (int i=0; i < 1000; i++) { in.put(Integer.toString(i), Integer.toString(i)); } String blob = crypter.wrap(in); Map<String, String> out = crypter.unwrap(blob, 0); for (int i=0; i < 1000; i++) { assertEquals(out.get(Integer.toString(i)), Integer.toString(i)); } }
@Test public void testManyEntries() throws Exception { Map<String, String> in = Maps.newHashMap(); for (int i=0; i < 1000; i++) { in.put(Integer.toString(i), Integer.toString(i)); } String blob = crypter.wrap(in); Map<String, String> out = crypter.unwrap(blob, 0); for (int i=0; i < 1000; i++) { assertEquals(out.get(Integer.toString(i)), Integer.toString(i)); } }
@Test public void testManyEntries() throws Exception { Map<String, String> in = Maps.newHashMap(); for (int i=0; i < 1000; i++) { in.put(Integer.toString(i), Integer.toString(i)); } String blob = crypter.wrap(in); Map<String, String> out = crypter.unwrap(blob); for (int i=0; i < 1000; i++) { assertEquals(out.get(Integer.toString(i)), Integer.toString(i)); } }
@Test public void testManyEntries() throws Exception { Map<String, String> in = Maps.newHashMap(); for (int i=0; i < 1000; i++) { in.put(Integer.toString(i), Integer.toString(i)); } String blob = crypter.wrap(in); Map<String, String> out = crypter.unwrap(blob); for (int i=0; i < 1000; i++) { assertEquals(out.get(Integer.toString(i)), Integer.toString(i)); } }
@Test(expected=BlobCrypterException.class) public void testBadKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("1123456789abcdef".getBytes(),HMACType.HMACSHA1); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); alt.unwrap(blob); }
@Test(expected=BlobCrypterException.class) public void testBadKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("1123456789abcdef".getBytes()); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); alt.unwrap(blob, 30); }
@Test public void testFixedKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("0123456789abcdef".getBytes(),HMACType.HMACSHA1); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); Map<String, String> out = alt.unwrap(blob); assertEquals("b", out.get("a")); }
@Test public void testFixedKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("0123456789abcdef".getBytes(),HMACType.HMACSHA1); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); Map<String, String> out = alt.unwrap(blob); assertEquals("b", out.get("a")); }