如何对密文进行编码
文件 abc.txt 有几行密文。我想在放入字符串 srr 之前将密文行编码为十六进制编码或 base64 。我有什么办法可以做到吗?
bufferedReader = new BufferedReader(new FileReader("abc.txt"));
String srr = null;
srr = bufferedReader.readLine()
the file abc.txt has several lines of ciphertext. i want to encode the line of ciphertext into hex encode or base64 before putting in string srr . is there any way i can do it ?
bufferedReader = new BufferedReader(new FileReader("abc.txt"));
String srr = null;
srr = bufferedReader.readLine()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
abc.txt
中存储了什么样的密文?如果它是二进制的,则不应使用FileReader
来读取它,因为FileReader
使用的某些字符编码可能会更改您的输入字节。请改用FileInputStream
。What kind of cipertext is stored in
abc.txt
? If it's binary, you shouldn't use aFileReader
to read it, becauseFileReader
is using some character encoding that could change your input bytes. Use aFileInputStream
instead.如果您想以 Base64 对其进行编码,则可以使用 Commons Codec:
http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html
或者您可以进行十六进制编码:
http://commons.apache.org/codec/apidocs/org/apache/ commons/codec/binary/Hex.html
If you want to encode it in Base64 then you can use Commons Codec:
http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html
or you can hex encode:
http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Hex.html