久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 RSAPrivateKey 獲取 RSAPrivateCrtKey?

How to get a RSAPrivateCrtKey from a RSAPrivateKey?(如何從 RSAPrivateKey 獲取 RSAPrivateCrtKey?)
本文介紹了如何從 RSAPrivateKey 獲取 RSAPrivateCrtKey?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個 java.security.interfaces.RSAPrivateKey 和對應的 java.security.interfaces.RSAPublicKey 包含(僅)模數、私有指數和公共指數.

I have a java.security.interfaces.RSAPrivateKey and the corresponding java.security.interfaces.RSAPublicKey containing (only) modulus, private exponent and public exponent.

如果我對 RSA 的理解正確,應該可以恢復 java.security.interfaces.RSAPrivateCrtKey 的數字(用于 CRT 密鑰).

If I understand RSA right, it should be possible to recover the numbers for java.security.interfaces.RSAPrivateCrtKey (for CRT keys).

如果是這樣,我該怎么做?(我假設已經有一些實現了).

If so, how do I do it? (I assume there is some implementation already).

推薦答案

這個是可以的,而且有比較快的算法找參數.下面是一些說明該算法的 Java 代碼.

It is possible to do this, and there is a relatively fast algorithm to find the parameters. Here is some Java code that illustrates the algorithm.

/**
 * Find a factor of n by following the algorithm outlined in Handbook of Applied Cryptography, section
 * 8.2.2(i). See http://cacr.uwaterloo.ca/hac/about/chap8.pdf.
 *
 */

private static BigInteger findFactor(BigInteger e, BigInteger d, BigInteger n) {
    BigInteger edMinus1 = e.multiply(d).subtract(BigInteger.ONE);
    int s = edMinus1.getLowestSetBit();
    BigInteger t = edMinus1.shiftRight(s);

    for (int aInt = 2; true; aInt++) {
        BigInteger aPow = BigInteger.valueOf(aInt).modPow(t, n);
        for (int i = 1; i <= s; i++) {
            if (aPow.equals(BigInteger.ONE)) {
                break;
            }
            if (aPow.equals(n.subtract(BigInteger.ONE))) {
                break;
            }
            BigInteger aPowSquared = aPow.multiply(aPow).mod(n);
            if (aPowSquared.equals(BigInteger.ONE)) {
                return aPow.subtract(BigInteger.ONE).gcd(n);
            }
            aPow = aPowSquared;
        }
    }

}

public static RSAPrivateCrtKey createCrtKey(RSAPublicKey rsaPub, RSAPrivateKey rsaPriv) throws NoSuchAlgorithmException, InvalidKeySpecException {

    BigInteger e = rsaPub.getPublicExponent();
    BigInteger d = rsaPriv.getPrivateExponent();
    BigInteger n = rsaPub.getModulus();
    BigInteger p = findFactor(e, d, n);
    BigInteger q = n.divide(p);
    if (p.compareTo(q) > 0) {
        BigInteger t = p;
        p = q;
        q = t;
    }
    BigInteger exp1 = d.mod(p.subtract(BigInteger.ONE));
    BigInteger exp2 = d.mod(q.subtract(BigInteger.ONE));
    BigInteger coeff = q.modInverse(p);
    RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(n, e, d, p, q, exp1, exp2, coeff);
    KeyFactory kf = KeyFactory.getInstance("RSA");
    return (RSAPrivateCrtKey) kf.generatePrivate(keySpec);

}

這篇關于如何從 RSAPrivateKey 獲取 RSAPrivateCrtKey?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Java Remove Duplicates from an Array?(Java從數組中刪除重復項?)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復調用失敗來自服務器的意外響應:在 Android 工作室中未經授權)
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES Error: Given final block not properly padded(AES 錯誤:給定的最終塊未正確填充)
Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 檢測不正確的密鑰)
AES-256-CBC in Java(Java 中的 AES-256-CBC)
主站蜘蛛池模板: 99热国产免费 | 岛国av在线免费观看 | 天天干狠狠 | 国产又爽又黄的视频 | 最新中文字幕在线 | 国产成人a亚洲精品 | 免费观看黄色片视频 | 狠狠久 | 中文字幕一区二区三区四区五区 | 91资源在线 | 福利视频一区二区 | 精品美女视频在线观看免费软件 | 久久久精品一区二区三区 | 日韩一区二区在线观看视频 | 一区二区精品 | 国产精品久久久久久久午夜片 | 亚洲国产精品va在线看黑人 | 超碰3| 在线国产99| 日本三级全黄三级a | 亚洲精品一区在线观看 | 亚洲精品电影 | 亚洲色在线视频 | 精品欧美一区二区三区久久久 | 亚洲国产精品久久人人爱 | 欧美一级视频免费看 | 久久久精品网站 | 久久久久www| 成人久久18免费网站图片 | 国产男女视频网站 | 久久久久久久av麻豆果冻 | 伊人久久大香线 | 国产精品一区二区三区在线 | 国产精品美女久久久久aⅴ国产馆 | 国产精品视频久久久 | 国产欧美一区二区三区在线看 | 国产日韩精品在线 | 天天搞天天操 | 欧美日韩一 | 91精品中文字幕一区二区三区 | 国产高清一区 |