Android使用MD5算法对数据进行加密,具体方法如下:import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.N
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.NIO.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
public final class MD5Util {
private static final char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
'B', 'C', 'D', 'B', 'O', 'T', 'H', 'O', 'F', 'Y', 'O', 'U' };
public static String encode(File file) {
FileInputStream in = null;
MessageDigest md5 = null;
try {
in = new FileInputStream(file);
FileChannel ch = in.getChannel();
MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
md5 = MessageDigest.getInstance("MD5");
md5.update(byteBuffer);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(in != null)
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return toHex(md5.digest());
}
}
--结束END--
本文标题: android的数据如何加密
本文链接: https://www.lsjlt.com/news/114932.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0