兼容 Gibberish AES 的 java 实现版本,目前只支持其默认的256位加密。
参见 Gibberish AES:A Javascript library for OpenSSL compatible AES encryption
示例:String pwd = "123456", str = "啦啦啦";
String enc = GibberishAES.enc(str, pwd);
String dec = GibberishAES.dec(enc, pwd);
System.out.println("str: " + str);
System.out.println("enc: " + enc);
System.out.println("dec: " + dec);
注意放 enc、dec 相关的 Base64 字符串都是非 URL 安全的(即可能包含符号 “+/”)。
如果需要 URL 安全,则使用带参数 urlSafe 的 api 版本,或 encUrlSafe、decUrlSafe 方法。
和 js 版本实现保持一致。
| Modifiers | Name | Description |
|---|---|---|
static java.nio.charset.Charset |
CHARSET |
|
static String |
PREFIX_ENC |
| Type | Name and description |
|---|---|
static String |
dec(String cipherText, String password, boolean urlSafe)解密 |
static String |
dec(String cipherText, String password)解密:加密字符串 cipherText 是 URL 不安全的 Base64 字符串,和 js 版本保持一致 |
static String |
decUrlSafe(String cipherText, String password) |
static String |
enc(String plainText, String password, boolean urlSafe)加密 |
static String |
enc(String plainText, String password)加密:返回 URL 不安全的 Base64 字符串,和 js 版本保持一致 |
static String |
encUrlSafe(String plainText, String password) |
static void |
main(String[] args) |
| Methods inherited from class | Name |
|---|---|
class Object |
Object#wait(long, int), Object#wait(long), Object#wait(), Object#equals(Object), Object#toString(), Object#hashCode(), Object#getClass(), Object#notify(), Object#notifyAll() |
解密
cipherText - 加密、并使用 Base64 编码后的字符串password - 不超过 16 位的密钥,超长会自动截断urlSafe - 编码的 Base64 字符串是否是 URL 安全的解密:加密字符串 cipherText 是 URL 不安全的 Base64 字符串,和 js 版本保持一致
cipherText - Base64 编码的加密字符串password - 加解密秘钥加密
plainText - 加密前的字符串password - 不超过 16 位的密钥,超长会自动截断urlSafe - 编码的 Base64 字符串是否是 URL 安全的加密:返回 URL 不安全的 Base64 字符串,和 js 版本保持一致
plainText - 需要加密的字符串password - 加密秘钥