SM4、AES、DES加解密算法性能比较
测试代码
public void encryDecry() throws Exception{
SM4StringEncryptor sm4 = new SM4StringEncryptor();
String path = "D:\\Users\\xlj\\Downloads\\sylog.txt";
File file = new File(path);
InputStreamReader reader = new InputStreamReader(new FileInputStream(path));
BufferedReader br = new BufferedReader(reader);
StringBuilder fileContent = new StringBuilder();
String line = "";
line = br.readLine();
while (line != null) {
line = br.readLine();
fileContent.append(line);
}
System.out.println("文件原始大小:" + fileContent.length() /1024/1024 + "Mb");
StringBuilder fileContent = new StringBuilder("xlj12442");
long startTime = System.currentTimeMillis();
String encryContent= sm4.encrypt(fileContent.toString());
System.out.println("sm4加密后:" + encryContent);
System.out.println("sm4加密后文件大小:" + encryContent.length() /1024/1024 + "Mb");
long endTime = System.currentTimeMillis();
System.out.println("sm4加密耗时:" + (endTime - startTime) + "ms");
String decryContent = sm4.decrypt(encryContent);
System.out.println("sm4解密后:" + decryContent);
System.out.println("sm4解密后文件大小:" + decryContent.length() /1024/1024 + "Mb");
long endTime1 = System.currentTimeMillis();
System.out.println("sm4解密耗时:" + (endTime1 - endTime) + "ms");
// aes
byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);
long aesStartTime = System.currentTimeMillis();
encryContent = aes.encryptHex(decryContent);
long esaEndTimeEncry = System.currentTimeMillis();
System.out.println("aes加密后:" + encryContent);
System.out.println("aes加密后文件大小:" + encryContent.length() /1024/1024 + "Mb");
System.out.println("aes加密耗时:" + (esaEndTimeEncry - aesStartTime) + "ms");
long aesEncryStartTime = System.currentTimeMillis();
decryContent = aes.decryptStr(encryContent, CharsetUtil.CHARSET_UTF_8);
long aesEncryEndTime = System.currentTimeMillis();
System.out.println("aes解密后:" + decryContent);
System.out.println("aes解密后文件大小:" + decryContent.length() /1024/1024 + "Mb");
System.out.println("aes解密耗时:" + (aesEncryEndTime - aesEncryStartTime) + "ms");
// des
key = SecureUtil.generateKey(SymmetricAlgorithm.DESede.getValue()).getEncoded();
SymmetricCrypto des = new SymmetricCrypto(SymmetricAlgorithm.DESede, key);
long desStartTime = System.currentTimeMillis();
encryContent = des.encryptHex(decryContent);
long desEndTimeEncry = System.currentTimeMillis();
System.out.println("des ede加密后:" + encryContent);
System.out.println("des ede加密后文件大小:" + encryContent.length() /1024/1024 + "Mb");
System.out.println("des ede加密耗时:" + (desEndTimeEncry - desStartTime) + "ms");
long desEncryStartTime = System.currentTimeMillis();
decryContent = des.decryptStr(encryContent, CharsetUtil.CHARSET_UTF_8);
long desEncryEndTime = System.currentTimeMillis();
System.out.println("des ede解密后:" + decryContent);
System.out.println("des ede解密后文件大小:" + decryContent.length() /1024/1024 + "Mb");
System.out.println("des ede解密耗时:" + (desEncryEndTime - desEncryStartTime) + "ms");*/
}
性能比较结果
加密算法 | 文件大小 | 加密耗时(ms) | 解密耗时(ms) |
---|---|---|---|
SM4 | 5M | 1596 | 841 |
AES | 5M | 201 | 447 |
DES | 5M | 317 | 669 |
SM4 | 620KB | 689 | 172 |
AES | 620KB | 109 | 186 |
DES | 620KB | 53 | 132 |
SM4 | 36KB | 487 | 34 |
AES | 36KB | 20 | 57 |
DES | 36KB | 9 | 14 |
SM4 | 6Bytes | 505 | 0 |
AES | 6Bytes | 13 | 24 |
DES | 6Bytes | 1 | 0 |
文章来源:https://www.toymoban.com/news/detail-539601.html
文章来源地址https://www.toymoban.com/news/detail-539601.html
到了这里,关于SM4、AES、DES加解密算法性能比较的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!