Skip to content

Commit

Permalink
feat: RsaUtil支持可指定keySize
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyQing committed Apr 26, 2024
1 parent 828b624 commit efada65
Showing 1 changed file with 14 additions and 3 deletions.
Expand Up @@ -77,8 +77,19 @@ private static KeyFactory getKeyFactory() throws NoSuchAlgorithmException {
* @throws NoSuchAlgorithmException
*/
public static KeyPair generateKeyPair() throws NoSuchAlgorithmException {
return generateKeyPair(DEFAULT_KEY_SIZE);
}

/**
* 生成并返回RSA密钥对
*
* @param keysize
* @return
* @throws NoSuchAlgorithmException
*/
public static KeyPair generateKeyPair(int keysize) throws NoSuchAlgorithmException {
KeyPairGenerator keyPairGen = getKeyPairGenerator();
keyPairGen.initialize(DEFAULT_KEY_SIZE, new SecureRandom());
keyPairGen.initialize(keysize, new SecureRandom());
return keyPairGen.generateKeyPair();
}

Expand Down Expand Up @@ -221,8 +232,8 @@ public static byte[] decrypt(PrivateKey privateKey, byte[] data) throws NoSuchAl
* {@code
* null}。
*
* @param publicKey 给定的公钥
* @param plaintext 字符串
* @param publicKey 给定的公钥
* @param plaintext 字符串(maxlength=keysize/8)
* @return 给定字符串的密文。
* @throws BadPaddingException
* @throws IllegalBlockSizeException
Expand Down

0 comments on commit efada65

Please sign in to comment.