public String wrap(Map<String, String> in) throws BlobCrypterException { Preconditions.checkArgument(!in.containsKey(TIMESTAMP_KEY), "No '%s' key allowed for BlobCrypter", TIMESTAMP_KEY); try { byte[] encoded = serializeAndTimestamp(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha1(hmacKey, cipherText); byte[] b64 = Base64.encodeBase64URLSafe(Crypto.concat(cipherText, hmac)); return new String(b64, UTF8); } catch (UnsupportedEncodingException e) { throw new BlobCrypterException(e); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
public String wrap(Map<String, String> in) throws BlobCrypterException { Preconditions.checkArgument(!in.containsKey(TIMESTAMP_KEY), "No '%s' key allowed for BlobCrypter", TIMESTAMP_KEY); try { byte[] encoded = serializeAndTimestamp(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha1(hmacKey, cipherText); byte[] b64 = Base64.encodeBase64URLSafe(Crypto.concat(cipherText, hmac)); return new String(b64, UTF8); } catch (UnsupportedEncodingException e) { throw new BlobCrypterException(e); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
public String wrap(Map<String, String> in) throws BlobCrypterException { try { byte[] encoded = serialize(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha(hmacKey, cipherText,hmacType.getName()); byte[] b64 = Base64.encodeBase64URLSafe(Bytes.concat(cipherText, hmac)); return CharsetUtil.newUtf8String(b64); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
public String wrap(Map<String, String> in) throws BlobCrypterException { try { byte[] encoded = serialize(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha(hmacKey, cipherText,hmacType.getName()); byte[] b64 = Base64.encodeBase64URLSafe(Bytes.concat(cipherText, hmac)); return CharsetUtil.newUtf8String(b64); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
public String wrap(Map<String, String> in) throws BlobCrypterException { try { byte[] encoded = serialize(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha(hmacKey, cipherText,hmacType.getName()); byte[] b64 = Base64.encodeBase64URLSafe(Bytes.concat(cipherText, hmac)); return CharsetUtil.newUtf8String(b64); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
@Test public void testAes128Cbc() throws Exception { byte[] key = Crypto.getRandomBytes(Crypto.CIPHER_KEY_LEN); for (byte i=0; i < 50; i++) { byte[] orig = new byte[i]; for (byte j=0; j < i; j++) { orig[j] = j; } byte[] cipherText = Crypto.aes128cbcEncrypt(key, orig); byte[] plainText = Crypto.aes128cbcDecrypt(key, cipherText); assertArrayEquals("Array of length " + i, orig, plainText); } }
@Test public void testAes128Cbc() throws Exception { byte[] key = Crypto.getRandomBytes(Crypto.CIPHER_KEY_LEN); for (byte i=0; i < 50; i++) { byte[] orig = new byte[i]; for (byte j=0; j < i; j++) { orig[j] = j; } byte[] cipherText = Crypto.aes128cbcEncrypt(key, orig); byte[] plainText = Crypto.aes128cbcDecrypt(key, cipherText); assertArrayEquals("Array of length " + i, orig, plainText); } }
@Test public void testAes128Cbc() throws Exception { byte[] key = Crypto.getRandomBytes(Crypto.CIPHER_KEY_LEN); for (byte i=0; i < 50; i++) { byte[] orig = new byte[i]; for (byte j=0; j < i; j++) { orig[j] = j; } byte[] cipherText = Crypto.aes128cbcEncrypt(key, orig); byte[] plainText = Crypto.aes128cbcDecrypt(key, cipherText); assertArrayEquals("Array of length " + i, orig, plainText); } }
@Test public void testAes128Cbc() throws Exception { byte[] key = Crypto.getRandomBytes(Crypto.CIPHER_KEY_LEN); for (byte i=0; i < 50; i++) { byte[] orig = new byte[i]; for (byte j=0; j < i; j++) { orig[j] = j; } byte[] cipherText = Crypto.aes128cbcEncrypt(key, orig); byte[] plainText = Crypto.aes128cbcDecrypt(key, cipherText); assertArrayEquals("Array of length " + i, orig, plainText); } }
@Test public void testAes128Cbc() throws Exception { byte[] key = Crypto.getRandomBytes(Crypto.CIPHER_KEY_LEN); for (byte i=0; i < 50; i++) { byte[] orig = new byte[i]; for (byte j=0; j < i; j++) { orig[j] = j; } byte[] cipherText = Crypto.aes128cbcEncrypt(key, orig); byte[] plainText = Crypto.aes128cbcDecrypt(key, cipherText); assertArrayEquals("Array of length " + i, orig, plainText); } }