List of utility methods to do AES Key Get
byte[] | initSecretKey() init secret key KeyGenerator kg = null; try { kg = KeyGenerator.getInstance(KEY_ALGORITHM); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return new byte[0]; kg.init(128); ... |
boolean | keyAreEqual(byte[] b1, byte[] b2) compare if the given two keys are equal if (b1.length != b2.length) { return false; for (int i = 0; i < b1.length; i++) { if (b1[i] != b2[i]) { return false; return true; |
Key | makeKey() make Key return makeKey(ENCRYPTION_KEY);
|
Key | makeKey(String passkey) make Key try { MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] key = md.digest(passkey.getBytes("UTF-8")); return new SecretKeySpec(key, "AES"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); ... |
Key | toKey(byte[] key) transfer secret key return new SecretKeySpec(key, KEY_ALGORITHM); |
byte[] | generateEncryptionSecret() generate Encryption Secret try { KeyGenerator generator = KeyGenerator.getInstance("AES"); generator.init(128); SecretKey key = generator.generateKey(); return key.getEncoded(); } catch (NoSuchAlgorithmException ex) { Log.w("keyutil", ex); return null; ... |