当前位置: 首页 > wzjs >正文

做设计的网站大连网站制作

做设计的网站,大连网站制作,企业宣传片拍摄制作,博客网站排名大全一、对称加密算法 对称加密算法采用相同的密钥来进行加密和解密操作。其优点是加密和解密速度快,不过密钥的管理和分发存在一定的安全风险。 1.1、DES(已不推荐使用) 这是早期的对称加密算法,密钥长度为 56 位。但由于密钥长度较短,如今已不…

一、对称加密算法

        对称加密算法采用相同的密钥来进行加密和解密操作。其优点是加密和解密速度快,不过密钥的管理和分发存在一定的安全风险。

1.1、DES(已不推荐使用)

这是早期的对称加密算法,密钥长度为 56 位。但由于密钥长度较短,如今已不太安全。

优点

  1. 历史悠久,算法公开,研究较为透彻,有很多相关的实现和工具。
  2. 加密和解密速度相对较快,在早期计算机性能有限的情况下具有一定优势。

缺点

  1. 密钥长度较短,只有 56 位,在现代计算能力下,容易受到暴力破解攻击。
  2. 安全性逐渐降低,目前已不推荐用于对安全性要求较高的场景。

加密

 // DES 加密public static String desEncrypt(String plainText, String key) throws Exception {DESKeySpec desKeySpec = new DESKeySpec(key.getBytes(StandardCharsets.UTF_8));SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");SecretKey secretKey = keyFactory.generateSecret(desKeySpec);Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");cipher.init(Cipher.ENCRYPT_MODE, secretKey);byte[] encryptedBytes = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));return Base64.getEncoder().encodeToString(encryptedBytes);}

解密

public static String desDecrypt(String encryptedText, String key) throws Exception {DESKeySpec desKeySpec = new DESKeySpec(key.getBytes(StandardCharsets.UTF_8));SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");SecretKey secretKey = keyFactory.generateSecret(desKeySpec);Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");cipher.init(Cipher.DECRYPT_MODE, secretKey);byte[] decodedBytes = Base64.getDecoder().decode(encryptedText);byte[] decryptedBytes = cipher.doFinal(decodedBytes);return new String(decryptedBytes, StandardCharsets.UTF_8);}

结果

public static void main(String[] args) throws Exception {String plainText = "感谢关注,精华内容将持续更新!";String desKey = "66666666"; // DES 密钥长度必须为 8 字节// DES 测试String desEncrypted = desEncrypt(plainText, desKey);String desDecrypted = desDecrypt(desEncrypted, desKey);System.out.println("DES 加密: " + desEncrypted);System.out.println("DES 解密: " + desDecrypted);}DES 加密: 7LqxGfmOgresnxwwXzlGBWqFt8hXuqd6E4BC0mLxaBAohvYPdvaZXSO45z9XA5GH
DES 解密: 感谢关注,精华内容将持续更新!
    • 1.2、AES

        目前应用广泛的对称加密算法,支持 128 位、192 位和 256 位的密钥长度,安全性较高,效率也不错。

优点

1.安全性高,支持 128 位、192 位和 256 位的密钥长度,能够有效抵御各种已知的攻击。

2.加密和解密速度快,性能优越,在硬件和软件实现上都有很好的表现。

3.被广泛应用于各种领域,成为了对称加密算法的主流选择。

缺点

1.对于一些对资源要求极高的小型设备,可能会有一定的性能开销。

加密

// AES 加密public static String aesEncrypt(String plainText, String key) throws Exception {SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);byte[] encryptedBytes = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));return Base64.getEncoder().encodeToString(encryptedBytes);}

解密

 // AES 解密public static String aesDecrypt(String encryptedText, String key) throws Exception {SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);byte[] decodedBytes = Base64.getDecoder().decode(encryptedText);byte[] decryptedBytes = cipher.doFinal(decodedBytes);return new String(decryptedBytes, StandardCharsets.UTF_8);}

结果

public static void main(String[] args) throws Exception {String plainText = "感谢关注,精华内容将持续更新!";String aesKey = "1234567812345678"; // AES 密钥长度可以为 16、24 或 32 字节// AES 测试String aesEncrypted = aesEncrypt(plainText, aesKey);String aesDecrypted = aesDecrypt(aesEncrypted, aesKey);System.out.println("AES 加密: " + aesEncrypted);System.out.println("AES 解密: " + aesDecrypted);}AES 加密: PUI7SM6+J4XvSDnioVneLtQDkBXchZlIF7k9v3fqe5Nwk8Polh+pBxR5RQmbHa7v
AES 解密: 感谢关注,精华内容将持续更新!
    1. 1.3、3DES

        它是 DES 的增强版本,通过多次使用 DES 算法来增加密钥长度,进而提高安全性。

优点

1.在 DES 的基础上进行了改进,通过多次使用 DES 算法,增加了密钥长度,提高了安全性。

2.兼容性好,由于是基于 DES 算法,在一些旧系统中可以继续使用。

缺点

1.加密和解密速度较慢,因为需要进行多次 DES 运算。

2.密钥长度相对较长,管理和存储成本较高。

加密

 // 3DES 加密public static String tripleDesEncrypt(String plainText, String key) throws Exception {DESedeKeySpec desEdeKeySpec = new DESedeKeySpec(key.getBytes(StandardCharsets.UTF_8));SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");SecretKey secretKey = keyFactory.generateSecret(desEdeKeySpec);Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");cipher.init(Cipher.ENCRYPT_MODE, secretKey);byte[] encryptedBytes = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));return Base64.getEncoder().encodeToString(encryptedBytes);}

解密

// 3DES 解密public static String tripleDesDecrypt(String encryptedText, String key) throws Exception {DESedeKeySpec desEdeKeySpec = new DESedeKeySpec(key.getBytes(StandardCharsets.UTF_8));SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");SecretKey secretKey = keyFactory.generateSecret(desEdeKeySpec);Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");cipher.init(Cipher.DECRYPT_MODE, secretKey);byte[] decodedBytes = Base64.getDecoder().decode(encryptedText);byte[] decryptedBytes = cipher.doFinal(decodedBytes);return new String(decryptedBytes, StandardCharsets.UTF_8);}

结果

public static void main(String[] args) throws Exception {String plainText = "感谢关注,精华内容将持续更新!";String tripleDesKey = "0123456789abcdef01234567"; // 3DES 密钥长度必须为 24 字节// 3DES 测试String tripleDesEncrypted = tripleDesEncrypt(plainText, tripleDesKey);String tripleDesDecrypted = tripleDesDecrypt(tripleDesEncrypted, tripleDesKey);System.out.println("3DES 加密: " + tripleDesEncrypted);System.out.println("3DES 解密: " + tripleDesDecrypted);}
    1. 1.4、Blowfish

        这是一种可变密钥长度的对称分组密码算法,密钥长度可以从 32 位到 448 位,具有较高的加密速度和安全性,适用于对速度要求较高的场景。

优点

1.密钥长度可变,范围从 32 位到 448 位,可以根据不同的安全需求进行调整。

2.加密和解密速度快,尤其是在 64 位块的加密操作上表现出色。

3.算法简单,易于实现,没有专利限制。

缺点

1.块大小固定为 64 位,在处理大数据时可能效率不如其他算法。

2.应用范围相对较窄,不如 AES 等算法普及。

加密

// Blowfish 加密public static String blowfishEncrypt(String plainText, String key) throws Exception {SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "Blowfish");Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);byte[] encryptedBytes = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));return Base64.getEncoder().encodeToString(encryptedBytes);}

解密

// Blowfish 解密public static String blowfishDecrypt(String encryptedText, String key) throws Exception {SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "Blowfish");Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);byte[] decodedBytes = Base64.getDecoder().decode(encryptedText);byte[] decryptedBytes = cipher.doFinal(decodedBytes);return new String(decryptedBytes, StandardCharsets.UTF_8);}

结果

public static void main(String[] args) throws Exception {String plainText = "感谢关注,精华内容将持续更新!";String blowfishKey = "abcdefghijklmnop";// Blowfish 测试String blowfishEncrypted = blowfishEncrypt(plainText, blowfishKey);String blowfishDecrypted = blowfishDecrypt(blowfishEncrypted, blowfishKey);System.out.println("Blowfish 加密: " + blowfishEncrypted);System.out.println("Blowfish 解密: " + blowfishDecrypted);}Blowfish 加密: HEKXerp2DpkPIHeIIt/cPBxub0z7jWWYKxZImxB2VOfDWIrH/dHVNqSP7gyHwyiU
Blowfish 解密: 感谢关注,精华内容将持续更新!
    1. 1.5、Twofish

        作为 Blowfish 算法的继任者,Twofish 同样是对称分组加密算法。它支持 128 位、192 位和 256 位的密钥长度,设计上考虑了安全性和性能的平衡,并且具有良好的灵活性和可扩展性。

优点

1.安全性高,设计上考虑了各种攻击方式,具有较好的抗攻击能力。

2.支持多种密钥长度,包括 128 位、192 位和 256 位。

3.算法灵活性高,可扩展性好。

缺点

1.实现相对复杂,需要一定的技术成本。

2.应用不如 AES 广泛,相关的工具和库相对较少。

引入依赖

<dependency><groupId>org.bouncycastle</groupId><artifactId>bcprov-jdk15on</artifactId><version>1.70</version>
</dependency>

加密

// Twofish 加密(需要 Bouncy Castle 库)public static String twofishEncrypt(String plainText, String key) throws Exception {Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "Twofish");Cipher cipher = Cipher.getInstance("Twofish/ECB/PKCS5Padding", "BC");cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);byte[] encryptedBytes = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));return Base64.getEncoder().encodeToString(encryptedBytes);}

解密

// Twofish 解密(需要 Bouncy Castle 库)public static String twofishDecrypt(String encryptedText, String key) throws Exception {Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "Twofish");Cipher cipher = Cipher.getInstance("Twofish/ECB/PKCS5Padding", "BC");cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);byte[] decodedBytes = Base64.getDecoder().decode(encryptedText);byte[] decryptedBytes = cipher.doFinal(decodedBytes);return new String(decryptedBytes, StandardCharsets.UTF_8);}

结果

public static void main(String[] args) throws Exception {String plainText = "感谢关注,精华内容将持续更新!";String twofishKey = "0123456789abcdef0123456789abcdef";// Twofish 测试String twofishEncrypted = twofishEncrypt(plainText, twofishKey);String twofishDecrypted = twofishDecrypt(twofishEncrypted, twofishKey);System.out.println("Twofish 加密: " + twofishEncrypted);System.out.println("Twofish 解密: " + twofishDecrypted);}Twofish 加密: Z9UhJb9JZT0++Do6zauZPwf5tOMc6gX2o4LE7pZLXcwTL4PJ6m4LGvobb9k7Uv1e
Twofish 解密: 感谢关注,精华内容将持续更新!

通过以上内容便可轻轻松松使用是对称加密算法.是不是超级简单.有任何问题欢迎留言哦!!!

重点!重点!重点!

遇到问题不用怕不如来我的知识库找找看,也许有意想不到的收获!!!

易网时代-易库资源-易库教程:.NET开发、Java开发、PHP开发、SqlServer技术、MySQL技术-开发资料大全-易网时代-易库资源-易库教程 (escdns.com)

http://www.dtcms.com/wzjs/586947.html

相关文章:

  • 佛山微网站推广哪家专业wordpress安装无法连接数据库
  • 企业网站管理系统 才能湖南岚鸿网站推广结束语
  • 装饰公司营销网站模板开平网站制作
  • 手机网站 制作教程wordpress做支付宝
  • ppt模板怎么做 下载网站大作设计网站
  • 网站域名在哪里申请深圳专业网站建设
  • 怎么提升网站加载速度大连百度seo
  • 网页制作企业网站作业专业企业网站建设定制
  • 如何制作网站赚钱忻州推广型网站开发
  • wordpress 登录空白百度关键词优化词精灵
  • 建设仿优酷视频网站互联网服务平台12123
  • 机械设备网站建设谷歌推广app
  • 网站制作的重要流程图淘宝店有给网站做优化am
  • 太原网站建设方案服务重庆网站备案注销
  • 京东 推广网站怎么做有必要自建网站做导购吗
  • 网站建设 长期待摊马云的网站是谁建设的
  • 中山网站开发公司咸宁网页定制
  • 深圳网站制作网络建设公司图片字体转wordpress
  • 网站后台建设用到哪些编程语言用yii框架做的网站如何搭建
  • 天津建设电工证查询网站中国国际贸易网官网
  • chatgpt网站挪威网站后缀
  • 好的建网站的公司管理系统软件有哪些
  • 个人备案网站做app王也踏青图照片
  • 网站验收模版襄阳网站建设楚翼网络
  • 网站整站优化推广方案网站建设需要学习什么
  • 企业黄页网站源码软件外包产业是什么
  • 黄楼企业建站流程wordpress搬家失败
  • 网站开发模式框架厦门网站设计公司找哪家厦门电商系统
  • 百度官网app汕头网站优化哪家好
  • 建设网站好难灰色关键词排名代做