Fx.crypto: APIs related to encryption and decryption, encoding and decoding
1. MD5
Fx.crypto.getMD5()
return type
MD5API
(1).Refer to MD5API
2. DE Sede
Fx.crypto.getDESede()
return type
DE Sede API
(1). Refer to DESedeAPI
3. Base64
Fx.crypto.getBase64()
return type
Base64API
(1). Refer to Base64API
4. SHA1
Fx.crypto.getSHA1()
return type
SHA1API
(1).Refer to SHA1API
5. URL encoding and decoding
Fx.crypto.getURL()
return type
URLAPI
(1). Refer to URLAPI
6. SHA
Fx.crypto.getSHA()
return type
SHAAPI
(1). Refer to SHAAPI
7. ECC Algorithm
Fx.crypto.getECC()
return type
ECCAPI
(1).Refer to ECCAPI
8. RSA Algorithm
Fx.crypto.getRSA()
return type
RSA API
(1).Refer to RSAAPI
9. HEX
Fx.crypto.getHex()
return type
HexAPI
(1). Refer to HexAPI
10. HMAC
Fx.crypto.getHmac()
return type
HmacAPI
(1). Refer to HmacAPI
11. A collection of symmetric algorithms
Fx.crypto.getSymmetry()
return type
SymmetryAPI
(1). Refer to SymmetryAPI
12. SM4 Chinese Symmetric Encryption Algorithm
Fx.crypto.getSM4()
return type
SM4API
(1). Refer to SM4API
13. SM2 Chinese asymmetric encryption algorithm
Fx.crypto.getSM2()
return type
SM2API
(1). Refer to SM2API
14. SM3 China Data Signature Algorithm
Fx.crypto.getSM3()
return type
SM3API
(1). Refer to SM3API
Reference class com.fxiaoke.functions.api.MD5API
1. Perform MD5 digest operation on the input bytes, and perform hexadecimal to string encoding on the byte[] operation result
encode(<byte[] data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | byte[] | data to be calculated |
return type
java.lang.String
Return value description
String
Java example
byte[] bts = {1, 2, 3};
Fx.crypto.getMD5().encode(bts);
Groovy example:
Fx.crypto.MD5.encode([1, 2] as byte[])
2. Perform MD5 digest operation on the input content
encode2Bytes(<byte[] data>)
Parameter Description
| parameter | type | description|
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | byte[] | data to be calculated |
return type
byte[]
Return value description
byte[]
Java example
byte[] bts = {1, 2, 3};
log.info(Fx.crypto.getMD5().encode2Bytes(bts));
Groovy example:
log.info(Fx.crypto.MD5.encode2Bytes([1, 2] as byte[]))
3. Perform MD5 digest operation on the input string, and perform hexadecimal to string encoding on the byte[] operation result
encode(<java.lang.String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | String | the data to be operated |
return type
java.lang.String
Return value description
String
Java example
Fx.crypto.getMD5().encode("fxiaoke");
Groovy example:
Fx.crypto.MD5.encode("fxiaoke")
Reference class com.fxiaoke.functions.api.DESedeAPI
1. DESede encryption
encode(<byte[] key>, <java.lang.String iv>, <byte[] data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | byte[] | encryption key |
| iv | String | initial vector |
| data | byte[] | encrypted data |
return type
byte[]
Return value description
byte[]
Java example
byte[] bts = {1, 2, 3};
Fx.crypto.getDESede().encode(Strings.toUTF8Bytes("123456789101112131415123116") ,"12345678", bts);
Groovy example:
Fx.crypto.DESede.encode(Strings.toUTF8Bytes("123456789101112131415123116") ,"12345678",[1,2] as byte[])
2. DESede decryption
decode(<byte[] key>, <java.lang.String iv>, <byte[] data>)
Parameter Description
| parameter | type | description|
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | byte[] | encryption key |
| iv | String | initial vector |
| data | byte[] | decrypted data |
return type
byte[]
Return value description
byte[]
Java example
byte[] bts = {1, 2, 3};
Fx.crypto.getDESede().decode(Strings.toUTF8Bytes("123456789101112131415123116") ,"12345678", bts);
Groovy example:
Fx.crypto.DESede.decode(Strings.toUTF8Bytes("123456789101112131415123116") ,"12345678", [-26, -74, -89, -3, 116, 71, -6, -26] as byte[])
Reference class com.fxiaoke.functions.api.Base64API
1. Base64 encoding
encode(<byte[] data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | byte[] | data to be encoded |
return type
java.lang.String
Return value description
String
Java example
byte[] bts = {1, 2, 3};
Fx.crypto.getBase64().encode(bts);
Groovy example:
Fx.crypto.base64.encode([1] as byte[])
2. Base64 decoding
decode(<java.lang.String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | String | The data to be decoded |
return type
byte[]
Return value description
byte[]
Java example
Fx.crypto.getBase64().decode("content");
Groovy example:
Fx.crypto.base64.decode("content")
3. Base64 decoding
decode(<byte[] data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | bytee[] | data to be decoded |
return type
byte[]
Return value description
byte[]
Java example
byte[] bts = {1, 2, 3};
Fx.crypto.getBase64().decode(bts);
Groovy example:
Fx.crypto.base64.decode([1, 2] as byte[])
Reference class com.fxiaoke.functions.api.SHA1API
1. Sha1 operation
encode(<byte[] data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | byte[] | data to be calculated |
return type
byte[]
Return value description
byte[]
Java example
byte[] bts = {1, 2, 3};
Fx.crypto.getSHA1().encode(bts);
Groovy example:
Fx.crypto.SHA1.encode([1, 2] as byte[])
2. Sha1 operation
encode(<String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | String | the data to be operated |
return type
byte[]
Return value description
byte[]
Java example
Fx.crypto.getSHA1().encode("data");
Groovy example:
Fx.crypto.SHA1.encode("data")
3. Sha1 operation, and add hex encoding to the result
hex(<byte[] data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | byte[] | data to be calculated |
return type
String
Return value description
byte[]
Java example
byte[] bts = {1, 2, 3};
Fx.crypto.getSHA1().hex(bts);
Groovy example:
Fx.crypto.SHA1.hex([1, 2] as byte[])
4. Sha1 operation, and add hex code to the result
hex(<String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ------------------------------------- |
| data | String | the data to be operated |
return type
String
Return value description
byte[]
Java example
Fx.crypto.getSHA1().hex("data");
Groovy example:
Fx.crypto.SHA1.hex("data")
5. hmacSHA1 operation
hmacSHA1(<String secret>, <String content>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| secret | String | operation secret key |
| content | String | Data to be operated |
return type
byte[]
Return value description
byte[]
Java example
byte[] bts = {1, 2, 3};
Fx.crypto.getSHA1().hmacSHA1("123", "hello");
Groovy example:
Fx.crypto.SHA1.hmacSHA1("123", "hello")
Reference class com.fxiaoke.functions.api.URLAPI
1. URL encoding
encode(<java.lang.String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | String | data to be encoded |
return type
com.fxiaoke.functions.model.APIResult
Return value description
String
Java example
APIResult ret = Fx.crypto.getURL().encode("encoded data");
if (ret. isError()) {
log.info(ret.message());
} else {
log.info(ret.getData());
}
Groovy example:
def(boolean error, String reuslt, String errorMessage) = Fx.crypto.URL.encode("encoded data")
2. URL decoding
decode(<java.lang.String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | String | The data to be decoded |
return type
com.fxiaoke.functions.model.APIResult
Return value description
String
Java example
APIResult ret = Fx.crypto.getURL().decode("%E7%BC%96%E7%A0%81%E7%9A%84%E6%95%B0%E6%8D%AE");
if (ret. isError()) {
log.info(ret.message());
} else {
log.info(ret.getData());
}
Groovy example:
def(boolean error, String result, String errorMessage) = Fx.crypto.URL.decode("%E7%BC%96%E7%A0%81%E7%9A%84%E6%95%B0%E6%8D% AE")
Reference class com.fxiaoke.functions.api.SHAAPI
1. sha256 operation
sha256(<byte[] data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | byte[] | data to be calculated |
return type
byte[]
Return value description
byte[]
Java example
byte[] bts = {1, 2, 3};
Fx.crypto.getSHA().sha256(bts);
Groovy example:
byte[] ss = Fx.crypto.SHA.sha256([1,2] as byte[])
2. sha256 operation
sha256(<java.lang.String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | String | the data to be operated |
return type
byte[]
Return value description
byte[]
Java example
byte[] bts = {1, 2, 3};
Fx.crypto.getSHA().sha256(bts);
Groovy example:
byte[] ss = Fx.crypto.SHA.sha256([1,2] as byte[])
3. HmacSHA256 operation
sha256HMAC(<java.lang.String secret>, <java.lang.String content>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| secret | String | operation secret key |
| content | String | Data to be operated |
return type
byte[]
Return value description
byte[]
Java example
byte[] ss = Fx.crypto.getSHA().sha256HMAC("1FA82F2D6DEE67E1A3E183BFA7E2FE67", "Hi everyone");
Groovy example:
byte[] ss = Fx.crypto.SHA.sha256HMAC('1FA82F2D6DEE67E1A3E183BFA7E2FE67', 'Hi everyone')
4. HmacSHA256 operation
sha256HMAC(<byte[] secret>, <java.lang.String content>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| secret | byte[] | operation secret key |
| content | String | Data to be operated |
return type
byte[]
Return value description
byte[]
Java example
byte[] bts = {1, 2, 3};
byte[] ss = Fx.crypto.getSHA().sha256HMAC(bts, "Hi everyone");
Groovy example:
byte[] ss = Fx.crypto.SHA.sha256HMAC([1,2] as byte[], 'Hi everyone')
5. Sha256 operation and Hex encoding for the encrypted result
sha256Hex(<java.lang.String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | String | the data to be operated |
return type
java.lang.String
Return value description
byte[]
Java example
String ss = Fx.crypto.getSHA().sha256Hex("Hi everyone");
Groovy example:
String ss = Fx.crypto.SHA.sha256Hex("Hi everyone")
6. And do Hex encoding for the operation result
sha256Hex(<byte[] data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | byte[] | data to be calculated |
return type
java.lang.String
Return value description
byte[]
Java example
byte[] bts = {1, 2, 3};
String ss = Fx.crypto.getSHA().sha256Hex(bts);
Groovy example:
String ss = Fx.crypto.SHA.sha256Hex([1,2] as byte[])
Reference class com.fxiaoke.functions.api.ECCAPI
1. ECC encryption
encrypt(<java.lang.String publicKey>, <java.lang.String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| publicKey | String | Encrypted public key, the generated algorithm is ECC, the format is Base64, X.509 standard storage |
| data | String | data to be encrypted |
return type
java.lang.String
Return value description
String
Java example
String publicKey = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEwGWFaJ9DfFEOerfs9ONP9nPozdJmpQ+tTy2xUknp8YVJnx/93dWXbRI6oGEwAVY26zWMcNPLtd8ekbPWbfSjUA==";
String str = "Hi everyone";
String encryptData = Fx.crypto.getECC().encrypt(publicKey, str);
Groovy example:
String publicKey = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEwGWFaJ9DfFEOerfs9ONP9nPozdJmpQ+tTy2xUknp8YVJnx/93dWXbRI6oGEwAVY26zWMcNPLtd8ekbPWbfSjUA=="
String str = "Hi everyone";
String encryptData = Fx.crypto.ECC.encrypt(publicKey, str);
2. ECC decryption
decrypt(<java. lang. String privateKey>, <java. lang. String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| privateKey | String | Decrypt the private key, the generated algorithm is ECC, the format is Base64, PKCS8 standard storage |
| data | String | data to be encrypted |
return type
java.lang.String
Return value description
String
Java example
String publicKey = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEwGWFaJ9DfFEOerfs9ONP9nPozdJmpQ+tTy2xUknp8YVJnx/93dWXbRI6oGEwAVY26zWMcNPLtd8ekbPWbfSjUA==";
String str = "Hi everyone";
String encryptData = Fx.crypto.getECC().encrypt(publicKey, str);
Groovy example:
String privateKey = "MD4CAQAwEAYHKoZIzj0CAQYFK4EEAAoEJzAlAgEBBCA1IMt9uJOEdW7kB69aTDmSRdxbpESSDUhNd9/d8hM5lw=="
String encryptData = Fx.crypto.ECC.encrypt(publicKey, str);
String decryptData = Fx.crypto.ECC.decrypt(privateKey, encryptData);```
### 3. ECC signature
> **sign(<java. lang. String privateKey>, <java. lang. String data>)**
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| privateKey | String | Signature private key, the generated algorithm is ECC, the format is Base64, PKCS8 standard storage |
| data | String | data to be encrypted |
return type
> java.lang.String
Return value description
> String
Java example
```java
String privateKey = "MD4CAQAwEAYHKoZIzj0CAQYFK4EEAAoEJzAlAgEBBCA1IMt9uJOEdW7kB69aTDmSRdxbpESSDUhNd9/d8hM5lw=";
String data = "hello world";
String sign = Fx.crypto.getECC().sign(privateKey, data);
Groovy example:
String privateKey = "MD4CAQAwEAYHKoZIzj0CAQYFK4EEAAoEJzAlAgEBBCA1IMt9uJOEdW7kB69aTDmSRdxbpESSDUhNd9/d8hM5lw=="
String data = "hello world"
String sign = Fx.crypto.ECC.sign(privateKey, data);
4. ECC signature verification
verifySign(<java.lang.String publicKey>, <java.lang.String sign>, <java.lang.String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| publicKey | String | Signature verification public key, the generated algorithm is ECC, the format is Base64, X.509 standard storage |
| sign | String | Content after signing |
| data | String | raw content |
return type
boolean
Return value description
boolean
Java example
String publicKey = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEwGWFaJ9DfFEOerfs9ONP9nPozdJmpQ+tTy2xUknp8YVJnx/93dWXbRI6oGEwAVY26zWMcNPLtd8ekbPWbfSjUA==";
String privateKey = "MD4CAQAwEAYHKoZIzj0CAQYFK4EEAAoEJzAlAgEBBCA1IMt9uJOEdW7kB69aTDmSRdxbpESSDUhNd9/d8hM5lw=";
String data = "hello world";
String sign = Fx.crypto.getECC().sign(privateKey, data);
log.info(Fx.crypto.getECC().verifySign(publicKey, sign, data));
Groovy example:
String publicKey = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEwGWFaJ9DfFEOerfs9ONP9nPozdJmpQ+tTy2xUknp8YVJnx/93dWXbRI6oGEwAVY26zWMcNPLtd8ekbPWbfSjUA=="
String privateKey = "MD4CAQAwEAYHKoZIzj0CAQYFK4EEAAoEJzAlAgEBBCA1IMt9uJOEdW7kB69aTDmSRdxbpESSDUhNd9/d8hM5lw=="
String data = "hello world"
String sign = Fx.crypto.ECC.sign(privateKey, data);
log.info(Fx.crypto.ECC.verifySign(publicKey, sign, data));
Reference class com.fxiaoke.functions.api.RSAAPI
1. RSA encryption
encrypt(<java. lang. String publicKey>, <java. lang. String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| publicKey | String | public key |
| data | String | data to be encrypted |
return type
java.lang.String
Return value description
String
Java example
String publicKey =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyVTOYRGyEZ2gjY+N4bsH" +
"suSjy/WevRi5X7MXklwpcyHdIYGrw8si+PoGnGivMhL/tfmOAglAeVviF+QeebDs" +
"6kKXwHB/PacSgx82Q4yQFS2UNfLOG6WQNIlPHZ1094cDFlVdcjxCSYcvgoBLZaws" +
"GelKmnjk1cBUhleeZElKLPj7mF3yq4hehNewUv5W/eByUCZ0CUqnWFnKPJ/xUYqX" +
"Fuvqx20cNYKhjAPKgDcKbNBGCKJW2uu1MMyDrxr5MKkn5gsDZ/P7AI0yy4UVbQ5C" +
"qG4rfuAJZ/WZ7fx9PrGEUBYt0NX33tcXAO/denOwMp9N5HgJlJGlJzJ7esx/ex3K" +
"wwIDAQAB";
String originalContent = "Original Content";
String text = Fx.crypto.getRSA().encrypt(publicKey,originalContent);
Fx.log.info(text);
Groovy example:
String publicKey =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyVTOYRGyEZ2gjY+N4bsH" +
"suSjy/WevRi5X7MXklwpcyHdIYGrw8si+PoGnGivMhL/tfmOAglAeVviF+QeebDs" +
"6kKXwHB/PacSgx82Q4yQFS2UNfLOG6WQNIlPHZ1094cDFlVdcjxCSYcvgoBLZaws" +
"GelKmnjk1cBUhleeZElKLPj7mF3yq4hehNewUv5W/eByUCZ0CUqnWFnKPJ/xUYqX" +
"Fuvqx20cNYKhjAPKgDcKbNBGCKJW2uu1MMyDrxr5MKkn5gsDZ/P7AI0yy4UVbQ5C" +
"qG4rfuAJZ/WZ7fx9PrGEUBYt0NX33tcXAO/denOwMp9N5HgJlJGlJzJ7esx/ex3K" +
"wwIDAQAB"
String originalContent = "Original Content"
String text = Fx.crypto.RSA.encrypt(publicKey,originalContent)
Fx.log.info(text)
2. RSA decryption
decrypt(<java. lang. String privateKey>, <java. lang. String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| privateKey | String | private key |
| data | String | The data to be decrypted |
return type
java.lang.String
Return value description
String
Java example
String privateKey =
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDJVM5hEbIRnaCN" +
"j43huwey5KPL9Z69GLlfsxeSXClzId0hgavDyyL4+gacaK8yEv+1+Y4CCUB5W+IX" +
"5B55sOzqQpfAcH89pxKDHzZDjJAVLZQ18s4bpZA0iU8dnXT3hwMWVV1yPEJJhy+C" +
"gEtlrCwZ6UqaeOTVwFSGV55kSUos+PuYXfKriF6E17BS/lb94HJQJnQJSqdYWco8" +
"n/FRipcW6+rHbRw1gqGMA8qANwps0EYIolba67UwzIOvGvkwqSfmCwNn8/sAjTLL" +
"hRVtDkKobit+4Aln9Znt/H0+sYRQFi3Q1ffe1xcA7916c7Ayn03keAmUkaUnMnt6" +
"zH97HcrDAgMBAAECggEASEA9/AncrIOz3Xl6AlsbTTDOM2DHAbeAtv5PZD/cxCuP" +
"7vlZCd+5gj4/5xuOW9sDl2uiccqeL68wuUAtS6CZtQwG55G3qAlwFEw8LgugnWkI" +
"+j9ThgppcOEh2k/qbPYvvnEOIvPLGhYAj8W4yRj7jqTxF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W17CrL9eR6My00oKXGcEMWJ+iGg7BSo" +
"JvxtK9uvc7rTlcbqxqD3dw==";
String text = "Hi everyone dgahd212";
String t3 = Fx.crypto.getRSA().decrypt(privateKey, text);
log. info(t3);
Groovy example:
String privateKey =
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDJVM5hEbIRnaCN" +
"j43huwey5KPL9Z69GLlfsxeSXClzId0hgavDyyL4+gacaK8yEv+1+Y4CCUB5W+IX" +
"5B55sOzqQpfAcH89pxKDHzZDjJAVLZQ18s4bpZA0iU8dnXT3hwMWVV1yPEJJhy+C" +
"gEtlrCwZ6UqaeOTVwFSGV55kSUos+PuYXfKriF6E17BS/lb94HJQJnQJSqdYWco8" +
"n/FRipcW6+rHbRw1gqGMA8qANwps0EYIolba67UwzIOvGvkwqSfmCwNn8/sAjTLL" +
"hRVtDkKobit+4Aln9Znt/H0+sYRQFi3Q1ffe1xcA7916c7Ayn03keAmUkaUnMnt6" +
"zH97HcrDAgMBAAECggEASEA9/AncrIOz3Xl6AlsbTTDOM2DHAbeAtv5PZD/cxCuP" +
"7vlZCd+5gj4/5xuOW9sDl2uiccqeL68wuUAtS6CZtQwG55G3qAlwFEw8LgugnWkI" +
"+j9ThgppcOEh2k/qbPYvvnEOIvPLGhYAj8W4yRj7jqTxF/RwsuDdtIR3HChNDUv+" +
"DX4SNWbAeyjceT4k/2bnO/+nFnylxLj9j+DajKy869APQk+4wmT8o/lEC/+MX2Uy" +
"IlC3YBGGwABJBIetAhj0RJi+6yjMk4GBnSGVPH1ehGy+cGTC6pFIupK+xYsGbd6S" +
"/XJo+3GEfnpUq8E9ZrCpPym0wjFJYIeL6sztaJnKgQKBgQDnGJU3XJYAdh7EpIHQ" +
"+yMtJPNIKZrZy4MZhWAPZRz6jwPocWlzg2B/jF4jydOlmccyXRGzqNyhSpYOxq7W" +
"uawVk2XEfqMCBnWBt/3j452gTQXkq1UQ/jLT/qZRvvzhbCun3uX9OdBWS3V4em6E" +
"yYi4SECaaGcdBY1jA5P6kElygwKBgQDfBxS+XKPpMvcOHrlSzXWQol47FA50Wx6S" +
"DgIE+lBmp+sylZe8ONBdnX0jQO9Ce75x3J/eY7dsnZxRC2B7ZW6H6pjt7ex0RBNk" +
"EfVjK7ykjttlXh2CX+WiT3oeY/DOz8pAU1deiUPAgIwR4ffbEgfhNQo1bf88lPhp" +
"+nMnR8XSwQKBgEA4EJ9F11lhecNjg7+zSl8tOX4AMcv8Rf49ligxDRCD1a4udgNn" +
"qtVHCJIhb/NA/J3+RwEKF+WqeHC6vbNl/XAxecJU/q99ZAIcQy2k/xSg0tZs1kLW" +
"oQFQbp+g1109VhRcWMU5369bYNWOEFBOQPQU//7orF7gQB4XzHOAzShJAoGAcUj+" +
"f2c9FvH9Td3LUsTsJ6hh5u5cHTw/ff7BhdfDyTEYJdyYc1IEfNjHPIX6QjHq3Zks" +
"V2EdRX2VbhEyU9uE1mMShSCqT7BYjScWFuabbpbl2EqDALtHQDfQluk640HmwN/U" +
"bD+a+4gQHfFC3bL976XqZpNV52bf+6zsmxI46MECgYA7auynp1+IUSrzF4sFtKfd" +
"YaPGn82p+PdDVKoA6hnjrIwnC5k6nR7XfSRyVt2n9myQYufoZs9WHwwme9FXEPYd" +
"qzJTqkMMtqh4jsGK1Uz95uUm3F0wZtvd0W17CrL9eR6My00oKXGcEMWJ+iGg7BSo" +
"JvxtK9uvc7rTlcbqxqD3dw=="
String text = "Hi everyone dgahd212"
String t3 = Fx.crypto.RSA.decrypt(privateKey, text)
log. info(t3)
3. RSA signature
sign(<java.lang.String algorithm>, <java.lang.String privateKey>, <java.lang.String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| algorithm | String | RSA algorithm |
| privateKey | String | private key |
| data | String | data to be signed |
return type
java.lang.String
Return value description
String
Java example
String privateKey =
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDJVM5hEbIRnaCN" +
"j43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hp" +
"+nMnR8XSwQKBgEA4EJ9F11lhecNjg7+zSl8tOX4AMcv8Rf49ligxDRCD1a4udgNn" +
"qtVHCJIhb/NA/J3+RwEKF+WqeHC6vbNl/XAxecJU/q99ZAIcQy2k/xSg0tZs1kLW" +
"oQFQbp+g1109VhRcWMU5369bYNWOEFBOQPQU//7orF7gQB4XzHOAzShJAoGAcUj+" +
"f2c9FvH9Td3LUsTsJ6hh5u5cHTw/ff7BhdfDyTEYJdyYc1IEfNjHPIX6QjHq3Zks" +
"V2EdRX2VbhEyU9uE1mMShSCqT7BYjScWFuabbpbl2EqDALtHQDfQluk640HmwN/U" +
"bD+a+4gQHfFC3bL976XqZpNV52bf+6zsmxI46MECgYA7auynp1+IUSrzF4sFtKfd" +
"YaPGn82p+PdDVKoA6hnjrIwnC5k6nR7XfSRyVt2n9myQYufoZs9WHwwme9FXEPYd" +
"qzJTqkMMtqh4jsGK1Uz95uUm3F0wZtvd0W17CrL9eR6My00oKXGcEMWJ+iGg7BSo" +
"JvxtK9uvc7rTlcbqxqD3dw==";
String signText = "Original Content";
String ret = Fx.crypto.getRSA().sign("SHA256", privateKey, signText);
Groovy example:
String privateKey =
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDJVM5hEbIRnaCN" +
"j43huwey5KPL9Z69GLlfsxeSXClzId0hgavDyyL4+gacaK8yEv+1+Y4CCUB5W+IX" +
"5B55sOzqQpfAcH89pxKDHzZDjJAVLZQ18s4bpZA0iU8dnXT3hwMWVV1yPEJJhy+C" +
"gEtlrCwZ6UqaeOTVwFSGV55kSUos+PuYXfKriF6E17BS/lb94HJQJnQJSqdYWco8" +
"n/FRipcW6+rHbRw1gqGMA8qANwps0EYIolba67UwzIOvGvkwqSfmCwNn8/sAjTLL" +
"hRVtDkKobit+4Aln9Znt/H0+sYRQFi3Q1ffe1xcA7916c7Ayn03keAmUkaUnMnt6" +
"zH97HcrDAgMBAAECggEASEA9/AncrIOz3Xl6AlsbTT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f+6zsmxI46MECgYA7auynp1+IUSrzF4sFtKfd" +
"YaPGn82p+PdDVKoA6hnjrIwnC5k6nR7XfSRyVt2n9myQYufoZs9WHwwme9FXEPYd" +
"qzJTqkMMtqh4jsGK1Uz95uUm3F0wZtvd0W17CrL9eR6My00oKXGcEMWJ+iGg7BSo" +
"JvxtK9uvc7rTlcbqxqD3dw=="
String signText = "Original Content"
def ret = Fx.crypto.RSA.sign("SHA256",privateKey,signText)
4. RSA signature verification
verifySign(<java.lang.String algorithm>, <java.lang.String publicKey>, <java.lang.String sign>, <java.lang.String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| algorithm | String | RSA algorithm |
| publicKey | String | public key |
| sign | String | Content after signing |
| data | String | raw content |
return type
boolean
Return value description
boolean
Java example
String publicKey =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyVTOYRGyEZ2gjY+N4bsH" +
"suSjy/WevRi5X7MXklwpcyHdIYGrw8si+PoGnGivMhL/tfmOAglAeVviF+QeebDs" +
"6kKXwHB/PacSgx82Q4yQFS2UNfLOG6WQNIlPHZ1094cDFlVdcjxCSYcvgoBLZaws" +
"GelKmnjk1cBUhleeZElKLPj7mF3yq4hehNewUv5W/eByUCZ0CUqnWFnKPJ/xUYqX" +
"Fuvqx20cNYKhjAPKgDcKbNBGCKJW2uu1MMyDrxr5MKkn5gsDZ/P7AI0yy4UVbQ5C" +
"qG4rfuAJZ/WZ7fx9PrGEUBYt0NX33tcXAO/denOwMp9N5HgJlJGlJzJ7esx/ex3K" +
"wwIDAQAB";
String signText = "BBmnxSmZkALrte4LotZ5agcUpQnxUt61/NzditHQDav37Mfv5rwUwzPRxiM6HdgKqFhEk1oPcJTiDRNqLwVe6YMM2nuENSaY/fuAfJRoicNHC8ggkVN0+TjM3NH3yLI8R1Mj5TIwLWjnUDo88IUL1smV6/xmnJ9yqlpPplq7z7Df9p4uYw4rdUpf6YYSyWcVDlHTYFd/+MEA6rWCewaeTV32ElYRw4TUG0iO7GdgqSmkWmzr/G1EYNAegD3anRA+dGTzigjH1tUkzQB08SANuXNSZ0wz6VHp5wsUyLWYHbzTrz3vS+xJczhrLkHh04IrBINfv/5EWaeTD5Rc7Y0g8Q==";
String orgText = "Original Content";
boolean ret = Fx.crypto.getRSA().verifySign("SHA256", publicKey, signText, orgText);
log. info(ret);
Groovy example:
String publicKey =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyVTOYRGyEZ2gjY+N4bsH" +
"suSjy/WevRi5X7MXklwpcyHdIYGrw8si+PoGnGivMhL/tfmOAglAeVviF+QeebDs" +
"6kKXwHB/PacSgx82Q4yQFS2UNfLOG6WQNIlPHZ1094cDFlVdcjxCSYcvgoBLZaws" +
"GelKmnjk1cBUhleeZElKLPj7mF3yq4hehNewUv5W/eByUCZ0CUqnWFnKPJ/xUYqX" +
"Fuvqx20cNYKhjAPKgDcKbNBGCKJW2uu1MMyDrxr5MKkn5gsDZ/P7AI0yy4UVbQ5C" +
"qG4rfuAJZ/WZ7fx9PrGEUBYt0NX33tcXAO/denOwMp9N5HgJlJGlJzJ7esx/ex3K" +
"wwIDAQAB"
String signText = """BBmnxSmZkALrte4LotZ5agcUpQnxUt61/NzditHQDav37Mfv5rwUwzPRxiM6HdgKqFhEk1oPcJTiDRNqLwVe6YMM2nuENSaY/fuAfJRoicNHC8ggkVN0+TjM3NH3yLI8R1Mj5TIwLWjnUDo88IUL1smV6/xmnJ9yqlpPplq7z7Df9p4uYw4rdUpf6YYSyWcVDlHTYFd/+MEA6rWCewaeTV32ElYRw4TUG0iO7GdgqSmkWmzr/G1EYNAegD3anRA+dGTzigjH1tUkzQB08SANuXNSZ0wz6VHp5wsUyLWYHbzTrz3vS+xJczhrLkHh04IrBINfv/5EWaeTD5Rc7Y0g8Q=="""
String orgText = """Original content"""
def ret = Fx.crypto.RSA.verifySign("SHA256", publicKey, signText, orgText)
log. info(ret)
Reference class com.fxiaoke.functions.api.HexAPI
1. Hex encoding
encode(<byte[] data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ---------------------------------------- |
| data | byte[] | data to be encoded |
return type
String
Return value description
String
Java example
byte[] data = Strings.toUTF8Bytes("123qeq&8|=23");
log.info(Fx.crypto.getHex().encode(data));
Groovy example:
byte[] data = Strings.toUTF8Bytes("123qeq&8|=23")
log.info(Fx.crypto.hex.encode(data))
2. Hex encoding
decode(<String data>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| data | String | The data to be decoded |
return type
byte[]
Return value description
byte[]
Java example
byte[] data = Fx.crypto.getHex().decode("31323371657126387c3d3233");
Groovy example:
byte[] data = Fx.crypto.hex.decode("31323371657126387c3d3233")
Reference class com.fxiaoke.functions.api.HmacAPI
1. Hmac encryption
encrypt(<java. lang. String algorithm>, <java. lang. String secret>, <java. lang. String content>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| algorithm | String | encryption algorithm |
| secret | String | secret key |
| content | String | Data that needs to be encrypted |
return type
byte[]
Return value description
byte[]
Java example
String algorithm = "HmacMD5";
String secret = "123";
String content = "Hi everyone";
byte[] data = Fx.crypto.getHmac().encrypt(algorithm, secret, content);
Groovy example:
String algorithm = "HmacMD5"
String secret = '123'
String content = 'Hi everyone'
byte[] data = Fx.crypto.hmac.encrypt(algorithm, secret, content)
Precautions
- Supported encryption algorithms HmacMD5, HmacSHA1, HmacSHA256, HmacSHA384, HmacSHA512
2. Hmac encryption
encrypt(<java.lang.String algorithm>, <byte[] secret>, <java.lang.String content>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| algorithm | String | encryption algorithm |
| secret | byte[] | secret key |
| content | String | Data that needs to be encrypted |
return type
byte[]
Return value description
byte[]
Java example
String algorithm = "HmacMD5";
byte[] secret = {1, 2, 3};
String content = "Hi everyone";
byte[] data = Fx.crypto.getHmac().encrypt(algorithm, secret, content);
log. info(data);
Groovy example:
String algorithm = "HmacMD5"
byte[] secret = [1, 2, 3]
String content = 'Hi everyone'
byte[] data = Fx.crypto.hmac.encrypt(algorithm, secret, content)
log. info(data)
Reference class com.fxiaoke.functions.api.SymmetryAPI
1. Symmetric encryption, iv type is String
encrypt(<java.lang.String algorithm>, <byte[] key>, <byte[] data>, <java.lang.String iv>, <java.lang.String mode>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| algorithm | String | Symmetric encryption algorithm |
| key | byte[] | secret key |
| data | byte[] | data to be encrypted |
| iv | String | optional arguments, vector |
| mode | String | optional parameter, encryption and padding mode |
return type
byte[]
Return value description
byte[]
Java example
byte[] input = Strings.toUTF8Bytes("Original content 12341");
byte[] key1 = Strings.toUTF8Bytes("1234567890abcdef"); //The key length is 16 bytes
byte[] e1 = Fx.crypto.getSymmetry().encrypt("AES", key1, input);
byte[] d1 = Fx.crypto.getSymmetry().decrypt("AES", key1, e1);
log.info(Strings.toUTF8String(d1));
Groovy example:
byte[] input = Strings.toUTF8Bytes("Original content 12341")
byte[] key1 = Strings.toUTF8Bytes("1234567890abcdef") //key length 16 bytes
byte[] e1 = Fx.crypto.symmetry.encrypt("AES", key1, input)
byte[] d1 = Fx.crypto.symmetry.decrypt("AES", key1, e1)
log.info(Strings.toUTF8String(d1))
Precautions
- Supported encryption algorithms AES\DES\3DES
2. Symmetric encryption, iv type is byte[]
encrypt(<java.lang.String algorithm>, <byte[] key>, <byte[] data>, <byte[] iv>, <java.lang.String mode>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| algorithm | String | |
| key | byte[] | secret key |
| data | byte[] | data to be encrypted |
| iv | byte[] | optional parameter, vector |
| mode | String | encryption and padding mode |
return type
byte[]
Return value description
byte[]
Java example
byte[] input = Strings.toUTF8Bytes("Original content 12341");
byte[] iv = {18, 52, 86, 120, -112, -85, -51, -17, 18, 52, 86, 120, -112, -85, -51, -17};
String mode = "AES/CBC/PKCS5Padding";
byte[] key1 = Strings.toUTF8Bytes("1234567890abcdef"); //The key length is 16 bytes
byte[] e1 = Fx.crypto.getSymmetry().encrypt("AES", key1, input, iv, mode);
byte[] d1 = Fx.crypto.getSymmetry().decrypt("AES", key1, e1, iv, mode);
log.info(Strings.toUTF8String(d1));
Groovy example:
byte[] input = Strings.toUTF8Bytes("Original content 12341")
byte[] iv = [18, 52, 86, 120, -112, -85, -51, -17, 18, 52, 86, 120, -112, -85, -51, -17]
String mode = "AES/CBC/PKCS5Padding"
byte[] key1 = Strings.toUTF8Bytes("1234567890abcdef") //key length 16 bytes
byte[] e1 = Fx.crypto.symmetry.encrypt("AES", key1, input, iv, mode)
byte[] d1 = Fx.crypto.symmetry.decrypt("AES", key1, e1, iv, mode)
log.info(Strings.toUTF8String(d1))
3. Symmetric decryption, iv type is String
decrypt(<java.lang.String algorithm>, <byte[] key>, <byte[] data>, <java.lang.String iv>, <java.lang.String mode>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| algorithm | String | Symmetric encryption algorithm |
| key | byte[] | secret key |
| data | byte[] | data to be encrypted |
| iv | String | optional arguments, vector |
| mode | String | optional parameter, encryption and padding mode |
return type
byte[]
Return value description
byte[]
Java example
byte[] input = Strings.toUTF8Bytes("Original content 12341");
String iv = "NIfb&95GUY86Gfgh";
String mode = "AES/CBC/PKCS5Padding";
byte[] key1 = Strings.toUTF8Bytes("1234567890abcdef"); //The key length is 16 bytes;
byte[] e1 = Fx.crypto.getSymmetry().encrypt("AES", key1, input, iv, mode);
byte[] d1 = Fx.crypto.getSymmetry().decrypt("AES", key1, e1, iv, mode);
log.info(Strings.toUTF8String(d1));
Groovy example:
byte[] input = Strings.toUTF8Bytes("Original content 12341")
String iv = "NIIfb&95GUY86Gfgh"
String mode = "AES/CBC/PKCS5Padding"
byte[] key1 = Strings.toUTF8Bytes("1234567890abcdef") //key length 16 bytes
byte[] e1 = Fx.crypto.symmetry.encrypt("AES", key1, input, iv, mode)
byte[] d1 = Fx.crypto.symmetry.decrypt("AES", key1, e1, iv, mode)
log.info(Strings.toUTF8String(d1))
4. Symmetric decryption, iv type is byte[]
decrypt(<java.lang.String algorithm>, <byte[] key>, <byte[] data>, <byte[] iv>, <java.lang.String mode>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ |-------------------------------------------------- ---------- |
| algorithm | String | |
| key | byte[] | secret key |
| data | byte[] | data to be encrypted |
| iv | byte[] | optional parameter, vector |
| mode | String | encryption and padding mode |
return type
byte[]
Return value description
byte[]
Java example
byte[] input = Strings.toUTF8Bytes("Original content 12341");
byte[] iv = {18, 52, 86, 120, -112, -85, -51, -17, 18, 52, 86, 120, -112, -85, -51, -17};
String mode = "AES/CBC/PKCS5Padding";
byte[] key1 = Strings.toUTF8Bytes("1234567890abcdef"); //The key length is 16 bytes
byte[] e1 = Fx.crypto.getSymmetry().encrypt("AES", key1, input, iv, mode);
byte[] d1 = Fx.crypto.getSymmetry().decrypt("AES", key1, e1, iv, mode);
log.info(Strings.toUTF8String(d1));
Groovy example:
byte[] input = Strings.toUTF8Bytes("Original content 12341")
byte[] iv = [18, 52, 86, 120, -112, -85, -51, -17, 18, 52, 86, 120, -112, -85, -51, -17]
String mode = "AES/CBC/PKCS5Padding"
byte[] key1 = Strings.toUTF8Bytes("1234567890abcdef") //key length 16 bytes
byte[] e1 = Fx.crypto.symmetry.encrypt("AES", key1, input, iv, mode)
byte[] d1 = Fx.crypto.symmetry.decrypt("AES", key1, e1, iv, mode)
log.info(Strings.toUTF8String(d1))
Reference class com.fxiaoke.functions.api.SM4API
1. SM4 encryption
encrypt(<java.lang.String key>, <java.lang.String data>, <java.lang.String mode>, <java.lang.String iv>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | String | secret key |
| data | String | data to be encrypted |
| mode | String | encryption and padding mode|
| iv | String | optional arguments, vector |
return type
byte[]
Return value description
byte[]
Java example
byte[] data = Fx.crypto.getSM4().encrypt("1234567812345678", "SM4UtilsTest", "SM4/CBC/PKCS5Padding", "8765432187654321");
Groovy example:
byte[] data = Fx.crypto.SM4.encrypt("1234567812345678", "SM4UtilsTest", "SM4/CBC/PKCS5Padding", "8765432187654321")
Precautions
- Supported encryption algorithms AES\DES\3DES
2. SM4 decryption
decrypt(<java.lang.String key>, <byte[] data>, <java.lang.String mode>, <java.lang.String iv>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | String | secret key |
| data | byte[] | data to be encrypted |
| mode | String | encryption and padding mode |
| iv | String | optional arguments, vector |
return type
byte[]
Return value description
byte[]
Java example
byte[] bts = {-127, 51, 92, -41, -14, 16, 27, 23, -122, -6, 98, 10, -6, 89, 94, 17};
byte[] data = Fx.crypto.getSM4().decrypt("1234567812345678", bts, "SM4/CBC/PKCS5Padding", "8765432187654321");
Groovy example:
byte[] data = Fx.crypto.SM4.decrypt("1234567812345678", [-127, 51, 92, -41, -14, 16, 27, 23, -122, -6, 98, 10, -6, 89, 94, 17] as byte[] , "SM4/CBC/PKCS5Padding", "8765432187654321")
Precautions
- Supported encryption algorithms AES\DES\3DES
Reference class com.fxiaoke.functions.api.SM2API
1. SM2 encryption
encode(<String input>, <String pubKey>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| input | String | data to be encrypted |
| pubKey| String | encrypted public key |
return type
String
Return value description
String
Java example
String data = Fx.crypto.getSM2().encode("Data you want to encrypt", "Public key")
Groovy example:
String data = Fx.crypto.SM2.encode("Data to encrypt", "Public key")
2. SM2 decryption
decode(<String input>, <String prvKey>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| input | String | data to decrypt |
| prvKey | String | private key |
return type
String
Return value description
String
Java example
String data = Fx.crypto.getSM2().decode("Data to be decrypted", "Public key")
Groovy example:
String data = Fx.crypto.SM2.decode("Data to be decrypted", "Private key")
3. SM2 signing
sign(<String privateKey>, <String body>, <String mode>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| privteKey | String | private key |
| body | String | The string to be signed |
| mode | String | signature algorithm mode |
return type
String
Return value description
String
Java example
String data = Fx.crypto.getSM2().sign( "private key", "data to be encrypted", "SM3withSM2")
Groovy example:
String data = Fx.crypto.SM2.sign( "private key", "data to be encrypted", "SM3withSM2")
Precautions
- The algorithm that supports signing supports SM3withSM2 and SM2
4. Obtain key pair
getKeys()
return type
String[]
Return value description
String[]
Java example
String[] keys = Fx.crypto.getSM2().getKeys()
Groovy example:
String[] keys = Fx.crypto.SM2.getKeys()
Precautions
- Obtain a public key and private key pair randomly, the first is the private key and the second is the public key
- The algorithm that supports signing supports SM3withSM2 and SM2
5. SM2 signature verification
verify(<String publicKeyStr>, <String msgStr>, <StringsignatureStr>, <String mode>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| publicKeyStr | String | public key |
| msgStr | String | plaintext |
| signatureStr | String | Ciphertext |
| mode | String | signature mode |
return type
boolean
Return value description
boolean
Java example
boolean data = Fx.crypto.getSM2().verify("Public key string", "information before signing", "ciphertext after signing", "SM3withSM2")
Groovy example:
boolean data = Fx.crypto.SM2.verify("Public key string", "information before signing", "ciphertext after signing", "SM3withSM2")
Precautions
- Signature verification supports SM2, SM3withSM2 two modes
- The algorithm that supports signing supports SM3withSM2 and SM2
Reference class com.fxiaoke.functions.api.SM3API
1. sm3 keyless signature
encrypt(<java. lang. String body>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| body | String | The string to be signed |
return type
java.lang.String
Return value description
String
Java example
String data = Fx.crypto.getSM3().encrypt("The data you want to encrypt")
Groovy example:
String data = Fx.crypto.SM3.encrypt("The data you want to encrypt")
2. sm3 keyless signature verification
verify(<java.lang.String str>, <java.lang.String hexString>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| str | String | previous data |
| hexString | String | encrypted data |
return type
boolean
Return value description
boolean
Java example
boolean isVerify = Fx.crypto.getSM3().verify("data before encryption","data after encryptionaccording to")
Groovy example:
boolean isVerify = Fx.crypto.SM3.verify("data before encryption", "data after encryption")