add methods

This commit is contained in:
Looly 2024-01-08 19:03:27 +08:00
parent a5b5497bf5
commit 6fba25ad7d
2 changed files with 24 additions and 0 deletions

View File

@ -64,6 +64,7 @@ public class KeyUtil {
public static final int DEFAULT_KEY_SIZE = 1024;
// region ----- generateKey
/**
* 生成 {@link SecretKey}仅用于对称加密和摘要算法密钥生成
*
@ -196,7 +197,24 @@ public class KeyUtil {
}
// endregion
/**
* 检查{@link KeyPair} 是否为空空的条件是
* <ul>
* <li>keyPair本身为{@code null}</li>
* <li>{@link KeyPair#getPrivate()}{@link KeyPair#getPublic()}都为{@code null}</li>
* </ul>
*
* @param keyPair 密钥对
* @return 是否为空
*/
// region ----- keyPair
public static boolean isEmpty(final KeyPair keyPair) {
if (null == keyPair) {
return false;
}
return null != keyPair.getPrivate() || null != keyPair.getPublic();
}
/**
* 生成RSA私钥仅用于非对称加密<br>
* 采用PKCS#8规范此规范定义了私钥信息语法和加密私钥语法<br>

View File

@ -435,6 +435,9 @@ public class ECKeyUtil {
* @since 5.5.9
*/
public static ECPrivateKeyParameters decodePrivateKeyParams(final byte[] privateKeyBytes) {
if (null == privateKeyBytes) {
return null;
}
try {
// 尝试D值
return toSm2PrivateParams(privateKeyBytes);
@ -468,6 +471,9 @@ public class ECKeyUtil {
* @since 5.5.9
*/
public static ECPublicKeyParameters decodePublicKeyParams(final byte[] publicKeyBytes) {
if(null == publicKeyBytes){
return null;
}
try {
// 尝试Q值
return toSm2PublicParams(publicKeyBytes);