/** * This method is deprecated. Please use {@link #encryptAES(String, byte[])} instead * * Encrypt a String with the AES encryption standard. Private key must have a length of 16 bytes * * @param value The String to encrypt * @param privateKey The key used to encrypt * @return An hexadecimal encrypted string */ @Deprecated public static String encryptAES(String value, String privateKey) { return encryptAES(value, privateKey.getBytes(Charsets.UTF_8)); }
/** * This method is deprecated. Please use {@link #encryptAES(String, byte[])} instead * * Encrypt a String with the AES encryption standard. Private key must have a length of 16 bytes * * @param value The String to encrypt * @param privateKey The key used to encrypt * @return An hexadecimal encrypted string */ @Deprecated public static String encryptAES(String value, String privateKey) { return encryptAES(value, privateKey.getBytes(Charsets.UTF_8)); }
/** * This method is deprecated, please use {@link #encryptAES(String, byte[])} instead * * Encrypt a String with the AES encryption standard. Private key must have a length of 16 bytes * * @param value The String to encrypt * @param privateKey The key used to encrypt * @param salt The salt * @return An hexadecimal encrypted string */ @Deprecated public static String encryptAES(String value, String privateKey, String salt) { return encryptAES(value, privateKey.getBytes(Charsets.UTF_8), salt.getBytes(Charsets.UTF_8)); }
/** * This method is deprecated, please use {@link #encryptAES(String, byte[])} instead * * Encrypt a String with the AES encryption standard. Private key must have a length of 16 bytes * * @param value The String to encrypt * @param privateKey The key used to encrypt * @param salt The salt * @return An hexadecimal encrypted string */ @Deprecated public static String encryptAES(String value, String privateKey, String salt) { return encryptAES(value, privateKey.getBytes(Charsets.UTF_8), salt.getBytes(Charsets.UTF_8)); }
public String encrypt(String message) { try { return Crypto.encryptAES(message, secret); } catch (UnexpectedException e) { Throwable cause = e.getCause(); if (cause instanceof InvalidKeyException) { LOGGER.error("Cannot encrypt/decrypt! Please download Java Crypto Extension pack from Oracle: http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136007.html"); } throw e; } }
public String encrypt(String message) { try { return Crypto.encryptAES(message, secret); } catch (UnexpectedException e) { Throwable cause = e.getCause(); if (cause instanceof InvalidKeyException) { LOGGER.error("Cannot encrypt/decrypt! Please download Java Crypto Extension pack from Oracle: http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136007.html"); } throw e; } }
/** * Generate a token string with secret key, ID and optionally payloads * @param secret the secret to encrypt to token string * @param seconds the expiration of the token in seconds * @param oid the ID of the token (could be customer ID etc) * @param payload the payload optionally indicate more information * @return an encrypted token string that is expiring in {@link Life#SHORT} time period */ public static String generateToken(byte[] secret, long seconds, String oid, String... payload) { long due = Life.due(seconds); List<String> l = new ArrayList<String>(2 + payload.length); l.add(oid); l.add(String.valueOf(due)); l.addAll(C.listOf(payload)); String s = S.join("|", l); return Crypto.encryptAES(s, secret); }