为什么不将大RSA密钥加密为唯一值?

问题描述 投票:0回答:1

我正在使用BigInteger的probablePrime方法计算两个2048位素数,如下所示:BigInteger.probablePrime(2048, new Random());。我们分别称这些素数为pq。我正在使用以下代码计算私有指数:BigInteger.TWO.multiply(r).add(BigInteger.ONE).divide(e);其中e等效于BigInteger.valueOf(3)r等效于BigInteger,其值是:(p - 1)(q - 1)

创建加密的BigInteger的过程如下:message.modPow(e, r),其中message是BigInteger。

假设我希望加密774356626352684872522728355634287624183747537718011900969524254770659766752605764866132228010801740792162094。这个大整数是“敏捷的棕色狐狸跳过了懒狗”。转换为二进制,然后转换为十进制。我的结果是464326058229369014486528960945777245568243099145851675968955902027904135435059026247893552949145149936678174588724345105141605583511438062567406913039976998983678282605288609470234530610515268764924240227134432014767865301287496131771559993377618477929696113174968779730288058725125905006272019930686696412137679303439126584

无论我运行上述代码多少次,它始终会加密为相同的精确值。它生成的素数似乎无关紧要-加密的值始终是该message值的上面的值。

现在这是特别的地方,如果我生成512位素数,则结果是唯一的。每次我运行上面的代码时,生成512位素数而不是2048甚至1024位素数,它每次运行都会生成一个唯一的结果。但是,如果我希望生成1024或2048位素数,则无论生成的素数如何,结果总是相同的。]

谁能解释为什么会发生这种情况,或者需要进行哪些更改才能使代码使用2048位素数生成唯一的加密整数?具体来说,为什么它适用于512或更低位的素数,而不适用于1024或更高位的素数?如果这不是最合理的问题,我深表歉意,所以请不要犹豫,要求澄清是否有混淆的地方。

谢谢。

编辑:这是产生问题的代码:

import java.io.IOException;
import java.math.BigInteger;
import java.security.SecureRandom;

public class Yeet {
    public static void main(String[] args) throws IOException {
        int t = (int) (System.currentTimeMillis() / 1000);

        byte[] date = new byte[]{
          (byte) (t >> 24),
          (byte) (t >> 16),
          (byte) (t >> 8),
          (byte) t,
        };  

        BigInteger p = BigInteger.probablePrime(2048, new SecureRandom(date));
        BigInteger q = BigInteger.probablePrime(2048, new SecureRandom(date));
        BigInteger e = BigInteger.valueOf(3);
        BigInteger r = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));

        BigInteger message = new BigInteger("774356626352684872522728355634287624183747537718011900969524254770659766752605764866132228010801740792162094");

        System.out.println(message.modPow(e, r));
    }
}

根据需要运行多次。它总是产生464326058229369014486528960945777245568243099145851675968955902027904135435059026247893552949145149936678174588724345105141605583511438062567406913039976998983678282605288609470234530610515268764924240227134432014767865301287496131771559993377618477929696113174968779730288058725125905006272019930686696412137679303439126584。现在,如果我们在第16和17行上将2048交换为512,则每次运行都会产生一个唯一值...

我正在使用BigInteger的probablePrime方法计算两个2048位素数,如下所示:BigInteger.probablePrime(2048,new Random());。分别称为质数p和q。我是...

java rsa biginteger
1个回答
0
投票

您正在执行原始/教科书RSA,其中加密只是具有公共指数的模块化指数。好吧,当然还有对整数的一些转换,更改或解释。

© www.soinside.com 2019 - 2024. All rights reserved.