Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java hutool 解密demo #11

Open
winters1214 opened this issue Aug 16, 2024 · 0 comments
Open

Java hutool 解密demo #11

winters1214 opened this issue Aug 16, 2024 · 0 comments

Comments

@winters1214
Copy link

// 密钥对生成地址 https://www.lzltool.com/SM2
private static final String PRIVATE_KEY = "";

private static final String PUBLIC_KEY = "";

public static String decryptStr(String cipherTextHex) {
    try {
        SM2 sm2 = SmUtil.sm2(PRIVATE_KEY, null); // 只需要私钥
        sm2.setMode(SM2Engine.Mode.C1C2C3); // 设置解密模式,JS 加密model 选:0
        byte[] decryptedBytes = sm2.decrypt(HexUtil.decodeHex(cipherTextHex), KeyType.PrivateKey);
        return Base64.decodeStr(StrUtil.utf8Str(decryptedBytes)); // 转换为字符串
    }catch (Exception e){
        log.error("decryptStr error: ", e);
    }
    return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant