Sign

Introduction

Hutool provides a simplified wrapper for java.security.Signature, named Sign, which is used for generating and verifying signatures.

For signature algorithms, Hutool encapsulates the Signature class from JDK. For more information, please refer to: https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#Signature:

// The RSA signature algorithm
NONEwithRSA

// The MD2/MD5 with RSA Encryption signature algorithm
MD2withRSA
MD5withRSA

// The signature algorithm with SHA-* and the RSA
SHA1withRSA
SHA256withRSA
SHA384withRSA
SHA512withRSA

// The Digital Signature Algorithm
NONEwithDSA

// The DSA with SHA-1 signature algorithm
SHA1withDSA

// The ECDSA signature algorithms
NONEwithECDSA
SHA1withECDSA
SHA256withECDSA
SHA384withECDSA
SHA512withECDSA

Usage

byte[] data = "我是一段测试字符串".getBytes();
Sign sign = SecureUtil.sign(SignAlgorithm.MD5withRSA);
// Generate the signature
byte[] signed = sign.sign(data);
// Verify the signature
boolean verify = sign.verify(data, signed);