System.err.println("私钥签名——公钥验证签名"); // 产生签名 String sign = CertificateUtils.signToBase64(data.getBytes("utf-8"), keyStorePath, alias, password); System.out.println("私钥签名:" + sign); boolean status = CertificateUtils.verifySign(data.getBytes("utf-8"), sign, certificatePath); System.err.println("公钥验签结果:" + status); // 公钥加密——私钥解密 System.out.println("\n公钥加密——私钥解密"); byte[] encrypt = CertificateUtils.encryptByPublicKey(data.getBytes("utf-8"), certificatePath); String encode = base64Encoding(encrypt); System.out.println("公钥加密:" + encode); //解密示例 byte[] decrypt = CertificateUtils.decryptByPrivateKey(Base64.getDecoder().decode(encode), keyStorePath, alias, password); String outputStr = new String(decrypt,"utf-8"); System.out.println("解密后:" + outputStr);