KeyPair pair = SecureUtil . generateKeyPair ( "SM2" ) ; String privateKeyStr = Base64 . getEncoder ( ) . encodeToString ( pair. getPrivate ( ) . getEncoded ( ) ) ; String publicKeyStr = Base64 . getEncoder ( ) . encodeToString ( pair. getPublic ( ) . getEncoded ( ) ) ; System . out. println ( "私钥 " + privateKeyStr) ; System . out. println ( "公钥 " + publicKeyStr) ; String content = "我是大鹏" ; SM2 sm2 = SmUtil . sm2 ( privateKeyStr, null ) ; String sign = sm2. signHex ( HexUtil . encodeHexStr ( content) ) ; SM2 sm2PublicKeyStr = SmUtil . sm2 ( null , publicKeyStr) ; boolean verify = sm2PublicKeyStr. verifyHex ( HexUtil . encodeHexStr ( content) , sign) ; SM2 sm2publicKeyStr = SmUtil . sm2 ( null , publicKeyStr) ; String encryptStr = sm2publicKeyStr. encryptBcd ( content, KeyType. PublicKey ) ; SM2 sm2privateKeyStr = SmUtil . sm2 ( privateKeyStr, null ) ; String decryptStr = StrUtil . utf8Str ( sm2privateKeyStr. decryptFromBcd ( encryptStr, KeyType. PrivateKey ) ) ;