示例#1
0
 /**
  * @param secret
  * @return
  */
 public String decrypt(String secret) {
   try {
     Cipher cipher = Cryptos.getAES(Cipher.ENCRYPT_MODE, keyHash, settings.cryptoKeySize());
     return Codecs.toUTF8(cipher.doFinal(Codecs.decodeBase64(secret, false)));
   } catch (BadPaddingException | IllegalBlockSizeException ex) {
     throw AppeException.wrap(ex);
   }
 }
示例#2
0
 /**
  * Generate 32 bytes secret
  *
  * @return
  */
 public String randomSecret() {
   return Codecs.encodeBase64(PRNG.nextBytes(32), false);
 }
示例#3
0
 /**
  * return a hash of a given secret if any.
  *
  * @param secret
  * @return
  */
 public String hash(String secret) {
   return Codecs.encodeBase64(
       Digests.sha2(settings.cryptoHashSalt(), Codecs.toBytes(secret)), false);
 }
示例#4
0
 /** @param settings */
 public CredentialsCrypto(AccountSettings settings) {
   this.settings = settings;
   this.keyHash = Digests.sha2(Codecs.toBytes(settings.cryptoKeySeed()));
 }