5556575859606162
public CryptoEngineImpl() { try { this.secureRandom = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException e) { throw new ShouldNeverHappenException(e); } }
8788899091929394
MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] result = digest.digest(data); return result; } catch (NoSuchAlgorithmException e) { throw new ShouldNeverHappenException(e); } }
113114115116117118119120
KeyGenerator keyGenerator = KeyGenerator.getInstance(ENCRYPTION_ALGORITHM); keyGenerator.init(KEY_SIZE_IN_BITS, secureRandom); return keyGenerator.generateKey(); } catch (NoSuchAlgorithmException e) { throw new ShouldNeverHappenException(e); } }
145146147148149150151152
} try { return s.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new ShouldNeverHappenException(e); } }
181182183184185186187188
byte[] encrypted = cipher.doFinal(data); return encrypted; } catch (GeneralSecurityException e) { throw new ShouldNeverHappenException(e); } }
198199200201202203204205
} try { return new String(bytes, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new ShouldNeverHappenException(e); } }
4344454647484950
firstLine = false; } return builder.toString(); } catch (IOException e) { throw new ShouldNeverHappenException(e); } }