- 签名和验证-Sign
- 介绍
- 使用
签名和验证-Sign
介绍
Hutool针对java.security.Signature做了简化包装,包装类为:Sign,用于生成签名和签名验证。
对于签名算法,Hutool封装了JDK的,具体介绍见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#Signature:
// The RSA signature algorithmNONEwithRSA// The MD2/MD5 with RSA Encryption signature algorithmMD2withRSAMD5withRSA// The signature algorithm with SHA-* and the RSASHA1withRSASHA256withRSASHA384withRSASHA512withRSA// The Digital Signature AlgorithmNONEwithDSA// The DSA with SHA-1 signature algorithmSHA1withDSA// The ECDSA signature algorithmsNONEwithECDSASHA1withECDSASHA256withECDSASHA384withECDSASHA512withECDSA
使用
byte[] data = "我是一段测试字符串".getBytes();Sign sign = SecureUtil.sign(SignAlgorithm.MD5withRSA);//签名byte[] signed = sign.sign(data);//验证签名boolean verify = sign.verify(data, signed);
