-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathSM3.java
32 lines (26 loc) · 827 Bytes
/
SM3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package cryptography.hashes.sm3;
import java.security.Security;
import org.spongycastle.crypto.digests.SM3Digest;
import org.spongycastle.util.encoders.Hex;
public class SM3 {
// Provider
static {
Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);
}
public static void main(String[] args) {
}
/**
* Source code:
* https://github.com/rtyley/spongycastle/blob/spongy-master/core/src/main/java/org/spongycastle/crypto/digests/SM3Digest.java
*
* @param input string
* @return Hash string
*/
public static String sm3Hash(final String input) {
SM3Digest sm3Digest = new SM3Digest();
sm3Digest.update(input.getBytes(), 0, input.length());
byte[] result = new byte[sm3Digest.getDigestSize()];
sm3Digest.doFinal(result, 0);
return Hex.toHexString(result);
}
}