稍后如何使用KeyGenerator生成的密钥?
我正在编写一个程序,它可以用 DES 进行加密和解密。解密时也应该使用加密过程中使用的相同密钥,对吗?我的问题是加密和解密在不同的机器上运行。这就是在加密过程中生成密钥的方式。
SecretKey key = KeyGenerator.getInstance("DES").generateKey();
所以,我想我会将密钥写入文件。但看起来我可以将 SecretKey 对象类型转换为字符串,但反之则不然!那么,如何提取文本文件中包含的密钥?并作为输入传递给该语句?
decipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
或者是否可以在加密和解密过程中将密钥作为用户的输入?
I'm writing a program which does both encryption and decryption in DES. The same key used during the encryption process should be used while decrypting too right? My problem is encryption and decryption are run on different machines. This is how the key is generated during the encryption process.
SecretKey key = KeyGenerator.getInstance("DES").generateKey();
So ,I thought I'll write the key to a file. But looks like I can typecast a SecretKey object to a String but not vice-versa! So, how do I extract the key contained in a text file? And pass as an input to this statement?
decipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
Or else is it possible to take the key as an input from the user during both the encryption and decryption process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样做:
然后稍后:
但请记住,当今 DES 并不安全(它可以相对容易地被暴力破解)。强烈考虑使用 AES(只需将“DES”替换为“AES”)。
Do this:
Then later:
But please remember that DES is unsecure today (it can be relatively easily bruteforced). Strongly consider using AES instead (just replace "DES" with "AES).