public class AESCipher
extends com.supermap.data.InternalHandleDisposable
// 密钥key 长度必须是 32 byte即256 bitString
key = "12345678abcdefgh12345678abcdefgh"; // 初始向量iv 长度必须是 16 byte即128 bitString
iv = "12345678abcdefgh";String
msg = "Hello the world!";AESCipher
cipher =AESCipher
.getInstance("CTR", key.getBytes(), iv.getBytes()); byte[] encrypted = cipher.encrypt(msg.getBytes()); byte[] result = cipher.decrypt(encrypted);String
resultString = newString
(result);
public static AESCipher getInstance(String transformation, byte[] key, byte[] iv)
transformation
- 模式字符串,目前支持'CTR'和'CBC'key
- 加解密密钥, 长度只能是 32 byte即256 bitiv
- 初始向量, 长度只能是 16 byte即128 bitIllegalArgumentException
- transformation为空或者长度为0IllegalArgumentException
- key为空IllegalArgumentException
- key长度不为32位IllegalArgumentException
- iv为空IllegalArgumentException
- iv长度不为16位public byte[] encrypt(byte[] input)
input
- 输入的缓冲区IllegalStateException
- 对象已经被disposeIllegalArgumentException
- 输入的缓冲区为空查看示例
public byte[] decrypt(byte[] input)
input
- 输入的缓冲区IllegalStateException
- 对象已经被disposeIllegalArgumentException
- 输入的缓冲区为空查看示例
public void dispose()
Copyright © 2021–2024 SuperMap. All rights reserved.