public byte[] decrypt(byte[] b) { ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayOutputStream out = new ByteArrayOutputStream(b.length); decrypt(in, out); return out.toByteArray(); }
public byte[] encrypt(byte[] b) { ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayOutputStream out = new ByteArrayOutputStream(b.length); encrypt(in, out); return out.toByteArray(); }
public AES(byte[] key) { this(generateKey(key)); }
@Test public void simpeTest() { for (int i = 0; i < 100; i++) { byte[] data1 = new byte[1024 * 1024]; Random random = new Random(); random.nextBytes(data1); String md5 = MD5.create().update(data1).asString(); AES aes = new AES("ololo key"); byte[] enc = aes.encrypt(data1); Assert.assertNotSame(md5, MD5.create().update(enc).asString()); aes = new AES("ololo key"); byte[] dec = aes.decrypt(enc); Assert.assertEquals(md5, MD5.create().update(dec).asString()); } } }
public AES() { try { KeyGenerator kg = KeyGenerator.getInstance("AES"); kg.init(128); key = kg.generateKey(); init(); } catch (NoSuchAlgorithmException ex) { throw Unchecked.rethrow(ex); } catch (NoSuchPaddingException ex) { throw Unchecked.rethrow(ex); } catch (InvalidKeyException ex) { throw Unchecked.rethrow(ex); } catch (InvalidAlgorithmParameterException ex) { throw Unchecked.rethrow(ex); } }
public byte[] toTransfer() { return toTransfer(key); }
public AES() { try { KeyGenerator kg = KeyGenerator.getInstance("AES"); kg.init(128); key = kg.generateKey(); init(); } catch (NoSuchAlgorithmException ex) { throw Unchecked.rethrow(ex); } catch (NoSuchPaddingException ex) { throw Unchecked.rethrow(ex); } catch (InvalidKeyException ex) { throw Unchecked.rethrow(ex); } catch (InvalidAlgorithmParameterException ex) { throw Unchecked.rethrow(ex); } }
public byte[] toTransfer() { return toTransfer(key); }
public AES(byte[] key) { this(generateKey(key)); }
public byte[] decrypt(byte[] b) { ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayOutputStream out = new ByteArrayOutputStream(b.length); decrypt(in, out); return out.toByteArray(); }
public byte[] encrypt(byte[] b) { ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayOutputStream out = new ByteArrayOutputStream(b.length); encrypt(in, out); return out.toByteArray(); }
/** * 16 chars max, 128-bit encription */ public AES(SecretKey key) { try { this.key = key; init(); } catch (NoSuchAlgorithmException ex) { throw Unchecked.rethrow(ex); } catch (NoSuchPaddingException ex) { throw Unchecked.rethrow(ex); } catch (InvalidKeyException ex) { throw Unchecked.rethrow(ex); } catch (InvalidAlgorithmParameterException ex) { throw Unchecked.rethrow(ex); } }
/** * 16 chars max, 128-bit encription */ public AES(String key) { this(generateKey(key.getBytes())); }
/** * 16 chars max, 128-bit encription */ public AES(SecretKey key) { try { this.key = key; init(); } catch (NoSuchAlgorithmException ex) { throw Unchecked.rethrow(ex); } catch (NoSuchPaddingException ex) { throw Unchecked.rethrow(ex); } catch (InvalidKeyException ex) { throw Unchecked.rethrow(ex); } catch (InvalidAlgorithmParameterException ex) { throw Unchecked.rethrow(ex); } }
/** * 16 chars max, 128-bit encription */ public AES(String key) { this(generateKey(key.getBytes())); }
/** * 16 chars max, 128-bit encription */ public static SecretKey generateKey(String key) { return generateKey(key.getBytes()); }
/** * 16 chars max, 128-bit encription */ public static SecretKey generateKey(String key) { return generateKey(key.getBytes()); }
public static SecretKey generateKeyAsMD5(String key) { return generateKey(MD5.create().update(key).asBytes()); }
public static SecretKey generateKeyAsMD5(String key) { return generateKey(MD5.create().update(key).asBytes()); }