有没有办法将AES密钥从base64转换为UTF-8字符串?
我正在使用以下方式生成AES-256 SecretKey:
KeyGenerator aesKeyGen = KeyGenerator.getInstance("AES");
aesKeyGen.init(256);
SecretKey secretKey = aesKeyGen.generateKey();
clientAesKey = secretKey.getEncoded();
有没有一种方法可以将字节数字视为字符串?对我有用的唯一方法是:
Base64.getEncoder().encodeToString(clientAesKey);
如果我打印并复制字符串,并尝试使用在线base64解码器进行解码,它会抱怨字符串不是UTF-8。
我知道它破坏了加密的目的,但是有什么方法可以将静态32个字符的长字符串分配为秘密键?
I am generating an AES-256 SecretKey using:
KeyGenerator aesKeyGen = KeyGenerator.getInstance("AES");
aesKeyGen.init(256);
SecretKey secretKey = aesKeyGen.generateKey();
clientAesKey = secretKey.getEncoded();
Is there a way that I can see the array of bytes as a string? Only way that works for me is this:
Base64.getEncoder().encodeToString(clientAesKey);
If I print it and copy the string, and try to decode it using an online Base64 decoder, it complains that the string is not UTF-8.
I know it defeats the purpose of encryptions, but is there a way that I can assign a static 32-characters long string as a secret key?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是“可视化”一个键的简单方法:
This is a simple way to 'visualize' a key: