【问题标题】:Why are two texts which are equal generate different encrypted text为什么两个相等的文本生成不同的加密文本
【发布时间】:2013-11-27 20:00:02
【问题描述】:

这个类:

import org.jasypt.util.text.BasicTextEncryptor;

    public class TestSame {

        public static void main(String args[]){

            BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
            textEncryptor.setPassword("test");

            System.out.println(textEncryptor.encrypt("test"));
            System.out.println(textEncryptor.encrypt("test"));

            System.out.println(textEncryptor.decrypt("Nv4nMcuVwsvWVuYD7Av44Q=="));
            System.out.println(textEncryptor.decrypt("bjU82X18p9gAivwomA+NpQ=="));

        }

    }

生成此输出:

n3G0M4YH8QjPU+YMYsfTmw==
ftokGN7dMKyLtKBaim2RTQ==
test
test

为什么密文不同?解密后的文本是一样的,那么由于每个加密文本不同,如何能够解密密码呢?

我希望使用相同密码和相同加密的相同文本会生成相同的加密文本,但情况似乎并非如此?

【问题讨论】:

    标签: java security encryption cryptography jasypt


    【解决方案1】:

    From the documentation

    如果使用随机盐生成器,同一消息的两个加密结果将始终不同(随机盐重合的情况除外)。这可以通过一次难以对数据集进行蛮力攻击并迫使攻击者对每个单独的加密数据片段执行蛮力攻击来加强安全性。

    【讨论】:

      猜你喜欢
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多