English
Fx.crypto
About 4589 wordsAbout 15 min
2026-01-09
1. getMD5 MD5
MD5
Fx.crypto.getMD5()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.MD5API
2. getDESede DESede
DESede
Fx.crypto.getDESede()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.DESedeAPI
3. getBase64 Base64
Base64
Fx.crypto.getBase64()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.Base64API
4. getSHA1 SHA1
SHA1
Fx.crypto.getSHA1()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.SHA1API
5. getURL URL Encoding/Decoding
URL Encoding/Decoding
Fx.crypto.getURL()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.URLAPI
6. getSHA SHA
SHA
Fx.crypto.getSHA()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.SHAAPI
7. getECC ECC Algorithm
ECC Algorithm
Fx.crypto.getECC()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.ECCAPI
8. getRSA RSA algorithm
RSA Algorithm
Fx.crypto.getRSA()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.RSAAPI
9. getHex HEX
HEX
Fx.crypto.getHex()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.HexAPI
10. getHmac HMAC
HMAC
Fx.crypto.getHmac()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.HmacAPI
11. getSymmetry Symmetric Algorithm Collection
Symmetric Algorithm Collection
Fx.crypto.getSymmetry()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.SymmetryAPI
12. getSM4 SM4 Chinese Symmetric Encryption Algorithm
SM4 Chinese Symmetric Encryption Algorithm
Fx.crypto.getSM4()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.SM4API
13. getSM2 SM2 Chinese Asymmetric Encryption Algorithm
SM2 Chinese Asymmetric Encryption Algorithm
Fx.crypto.getSM2()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.SM2API
14. getSM3 SM3 Chinese Cryptographic Hash Algorithm
SM3 Chinese Cryptographic Hash Algorithm
Fx.crypto.getSM3()
Reference Interface
- Reference guide: com.fxiaoke.functions.api.SM3API
Reference object com.fxiaoke.functions.api.MD5API
1. encode performs MD5 digest computation on the input bytes and converts the byte[] result into a hexadecimal string encoding.
Performs MD5 digest calculation on the input bytes and encodes the byte[] result into a hexadecimal string.
MD5API.encode(<String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | String | Data to be processed | Y |
Code examples
def str = "testtest"
def encode1 = Fx.crypto.MD5.encode(str)
log.info(encode1)//05A671C66AEFEA124CC08B76EA6D30BB
def encode = Fx.crypto.MD5.encode(str.getBytes())
log.info(encode) //05A671C66AEFEA124CC08B76EA6D30BB
def encodeByte = Fx.crypto.MD5.encode2Bytes(str.getBytes())
log.info(encodeByte)2. encode2Bytes performs MD5 digest computation on the input content
Perform MD5 digest computation on the input content
MD5API.encode2Bytes(<byte[] data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | byte[] | Data to be processed | Y |
Code examples
def str = "testtest"
def encode1 = Fx.crypto.MD5.encode(str)
log.info(encode1)//05A671C66AEFEA124CC08B76EA6D30BB
def encode = Fx.crypto.MD5.encode(str.getBytes())
log.info(encode) //05A671C66AEFEA124CC08B76EA6D30BB
def encodeByte = Fx.crypto.MD5.encode2Bytes(str.getBytes())
log.info(encodeByte)3. encode performs MD5 digest computation on the input string and converts the byte[] result into a hexadecimal string encoding.
Performs MD5 digest computation on the input string and converts the byte[] result into a hexadecimal string encoding.
MD5API.encode(<String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | String | Data to be processed | Y |
Code examples
def str = "testtest"
def encode1 = Fx.crypto.MD5.encode(str)
log.info(encode1)//05A671C66AEFEA124CC08B76EA6D30BB
def encode = Fx.crypto.MD5.encode(str.getBytes())
log.info(encode) //05A671C66AEFEA124CC08B76EA6D30BB
def encodeByte = Fx.crypto.MD5.encode2Bytes(str.getBytes())
log.info(encodeByte)Reference object com.fxiaoke.functions.api.DESedeAPI
1. encode DESede encryption
DESede Encryption
DESedeAPI.encode(<byte[] key>, <byte[] data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| key | byte[] | Encryption key, 24+ characters required | Y |
| data | byte[] | Data to be encoded | Y |
Code examples
def key = "12345678123456781234567812" //Key length >=24 characters
def iv = "12345678" //8-character iv
def data = "testtest" //Data to encrypt
def encode = Fx.crypto.DESede.encode(Strings.toUTF8Bytes(key), iv, data.getBytes())
log.info(encode)
def decode = Fx.crypto.DESede.decode(Strings.toUTF8Bytes(key), iv, encode)
log.info(Strings.toUTF8String(decode)) //testtestNotice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
Owner:斯作益seth
2. decode DESede decryption
DESede Decryption
DESedeAPI.decode(<byte[] key>, <byte[] data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| key | byte[] | Encryption key, 24+ bytes required | Y |
| data | byte[] | Data to be decoded | Y |
Code examples
def key = "12345678123456781234567812" //Key length >=24 characters
def iv = "12345678" //8-character iv
def data = "testtest" //Data to encrypt
def encode = Fx.crypto.DESede.encode(Strings.toUTF8Bytes(key), iv, data.getBytes())
log.info(encode)
def decode = Fx.crypto.DESede.decode(Strings.toUTF8Bytes(key), iv, encode)
log.info(Strings.toUTF8String(decode)) //testtestNotice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
Owner:斯作益seth
Reference object com.fxiaoke.functions.api.Base64API
1. encode Base64 encoding
Base64 Encoding
Base64API.encode(<byte[] data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | byte[] | Data to be encoded | Y |
Code examples
def str = "testtest"
def encode = Fx.crypto.base64.encode(str.getBytes())
log.info(encode) //dGVzdHRlc3Q=
def decode = Fx.crypto.base64.decode(encode)
log.info(StringUtils.toUTF8String(decode)) //testtest
def decode2 = Fx.crypto.base64.decode(encode.getBytes())
log.info(StringUtils.toUTF8String(decode2)) //testtest2. decode Base64 decoding
Base64 Decoding
Base64API.decode(<String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | String | Data to be decoded | Y |
Code examples
def str = "testtest"
def encode = Fx.crypto.base64.encode(str.getBytes())
log.info(encode) //dGVzdHRlc3Q=
def decode = Fx.crypto.base64.decode(encode)
log.info(StringUtils.toUTF8String(decode)) //testtest
def decode2 = Fx.crypto.base64.decode(encode.getBytes())
log.info(StringUtils.toUTF8String(decode2)) //testtest3. decode Base64 decoding
Base64 Decoding
Base64API.decode(<byte[] data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | byte[] | Data to be decoded | Y |
Code examples
def str = "testtest"
def encode = Fx.crypto.base64.encode(str.getBytes())
log.info(encode) //dGVzdHRlc3Q=
def decode = Fx.crypto.base64.decode(encode)
log.info(StringUtils.toUTF8String(decode)) //testtest
def decode2 = Fx.crypto.base64.decode(encode.getBytes())
log.info(StringUtils.toUTF8String(decode2)) //testtestReference object com.fxiaoke.functions.api.SHA1API
1. SHA1 encoding operation
SHA1 computation
SHA1API.encode()
Code examples
Fx.crypto.SHA1.encode([1, 2] as byte[])Notice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
Owner:斯作益seth
2. SHA1 encoding operation
SHA1 computation
SHA1API.encode()
Code examples
Fx.crypto.SHA1.encode("data")Notice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
Owner:斯作益seth
3. Compute SHA-1 hash and append the result with hex encoding
Perform SHA1 hashing and append the result with hex encoding
SHA1API.hex()
Code examples
Fx.crypto.SHA1.hex([1, 2] as byte[])Owner:斯作益seth
4. Compute SHA-1 hash and append the result with hex encoding
Perform SHA-1 hashing and append the result with hex encoding
SHA1API.hex()
Code examples
Fx.crypto.SHA1.hex("data")Owner:斯作益seth
5. hmacSHA1 hmacSHA1 computation
HMAC-SHA1 computation
SHA1API.hmacSHA1()
Code examples
Fx.crypto.SHA1.hmacSHA1("123", "hello")Owner:斯作益seth
Reference object com.fxiaoke.functions.api.URLAPI
1. encode URL encoding
URL Encoding
URLAPI.encode(<String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | String | Data to be encoded | Y |
Code examples
def str = 'name=Ichabod+Crane&gender=male&status=missing'
String encode = Fx.crypto.URL.encode(str).result()
log.info(encode) //name%3DIchabod%2BCrane%26gender%3Dmale%26status%3Dmissing
String decode = Fx.crypto.URL.decode(encode).result()
log.info(decode) //name%3DIchabod%2BCrane%26gender%3Dmale%26status%3Dmissing2. decode URL
URL Decoding
URLAPI.decode(<String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | String | Data to be decoded | Y |
Code examples
def str = 'name=Ichabod+Crane&gender=male&status=missing'
String encode = Fx.crypto.URL.encode(str).result()
log.info(encode) //name%3DIchabod%2BCrane%26gender%3Dmale%26status%3Dmissing
String decode = Fx.crypto.URL.decode(encode).result()
log.info(decode) //name%3DIchabod%2BCrane%26gender%3Dmale%26status%3DmissingOwner:斯作益seth
Reference object com.fxiaoke.functions.api.SHAAPI
1. sha256 SHA256 hash operation
SHA-256 computation
SHAAPI.sha256(<byte[] data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | byte[] | Data to be processed | Y |
Code examples
def str = 'testtest'
byte[] sha1 = Fx.crypto.SHA.sha256(str)
byte[] sha2 = Fx.crypto.SHA.sha256(str.getBytes())Notice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
2. sha256 SHA256 computation
SHA-256 computation
SHAAPI.sha256(<String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | String | Data to be processed | Y |
Code examples
def str = 'testtest'
byte[] sha1 = Fx.crypto.SHA.sha256(str)
byte[] sha2 = Fx.crypto.SHA.sha256(str.getBytes())Notice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or a plain string, as the conversion methods to byte[] differ accordingly.
3. sha256HMAC HmacSHA256 computation
HmacSHA256 computation
SHAAPI.sha256HMAC(<String secret>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| secret | String | Secret key | Y |
| data | String | Data to be processed | Y |
Code examples
def secret = '12345678'
def str = 'testtest'
byte[] sha1 = Fx.crypto.SHA.sha256HMAC(secret, str)
byte[] sha2 = Fx.crypto.SHA.sha256HMAC(secret.getBytes(), str)4. sha256HMAC HmacSHA256 computation
HmacSHA256 computation
SHAAPI.sha256HMAC(<byte[] secret>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| secret | byte[] | Secret key | Y |
| data | String | Data to be processed | Y |
Code examples
def secret = '12345678'
def str = 'testtest'
byte[] sha1 = Fx.crypto.SHA.sha256HMAC(secret, str)
byte[] sha2 = Fx.crypto.SHA.sha256HMAC(secret.getBytes(), str)5. sha256Hex Performs SHA-256 hashing and encodes the result in Hex format
Perform SHA256 hashing and encode the encrypted result in Hex format
SHAAPI.sha256Hex(<String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | String | Data to be processed | Y |
Code examples
def str = 'testtest'
def hex1 = Fx.crypto.SHA.sha256Hex(str)
log.info(hex1) //37268335dd6931045bdcdf92623ff819a64244b53d0e746d438797349d4da578
def hex2 = Fx.crypto.SHA.sha256Hex(str)
log.info(hex2) //37268335dd6931045bdcdf92623ff819a64244b53d0e746d438797349d4da5786. sha256Hex and perform Hex encoding on the operation result
and perform Hex encoding on the operation result
SHAAPI.sha256Hex(<byte[] data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | byte[] | Data to be processed | Y |
Code examples
def str = 'testtest'
def hex1 = Fx.crypto.SHA.sha256Hex(str)
log.info(hex1) //37268335dd6931045bdcdf92623ff819a64244b53d0e746d438797349d4da578
def hex2 = Fx.crypto.SHA.sha256Hex(str)
log.info(hex2) //37268335dd6931045bdcdf92623ff819a64244b53d0e746d438797349d4da578Reference object com.fxiaoke.functions.api.ECCAPI
1. encrypt ECC encryption
ECC Encryption
ECCAPI.encrypt(<String publicKey>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| publicKey | String | Encryption public key, generated using ECC algorithm, Base64 encoded, stored in X.509 standard format | Y |
| data | String | Data to be encrypted | Y |
Code examples
String publicKey = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEwGWFaJ9DfFEOerfs9ONP9nPozdJmpQ+tTy2xUknp8YVJnx/93dWXbRI6oGEwAVY26zWMcNPLtd8ekbPWbfSjUA=="
String str = "testtest";
String encryptData = Fx.crypto.ECC.encrypt(publicKey, str);
log.debug(encryptData) //dGVzdHRlc3Q=
String privateKey = "MD4CAQAwEAYHKoZIzj0CAQYFK4EEAAoEJzAlAgEBBCA1IMt9uJOEdW7kB69aTDmSRdxbpESSDUhNd9/d8hM5lw=="
String decryptData = Fx.crypto.ECC.decrypt(privateKey, encryptData);
log.info(decryptData) //testtestNotice
- Public and private keys are used in pairs
2. decrypt ECC decryption
ECC Decryption
ECCAPI.decrypt(<String privateKey>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| privateKey | String | Decryption private key generated using ECC algorithm, Base64 encoded and stored in PKCS#8 standard format | Y |
| data | String | Data to be encrypted | Y |
Code examples
String publicKey = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEwGWFaJ9DfFEOerfs9ONP9nPozdJmpQ+tTy2xUknp8YVJnx/93dWXbRI6oGEwAVY26zWMcNPLtd8ekbPWbfSjUA=="
String str = "testtest";
String encryptData = Fx.crypto.ECC.encrypt(publicKey, str);
log.debug(encryptData) //dGVzdHRlc3Q=
String privateKey = "MD4CAQAwEAYHKoZIzj0CAQYFK4EEAAoEJzAlAgEBBCA1IMt9uJOEdW7kB69aTDmSRdxbpESSDUhNd9/d8hM5lw=="
String decryptData = Fx.crypto.ECC.decrypt(privateKey, encryptData);
log.info(decryptData) //testtestNotice
- Public and private keys are used in pairs.
3. sign ECC signature
ECC Signature
ECCAPI.sign(<String privateKey>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| privateKey | String | Signing private key in ECC algorithm, Base64 encoded, stored in PKCS8 standard format | Y |
| data | String | Data to be encrypted | Y |
Code examples
String publicKey = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEwGWFaJ9DfFEOerfs9ONP9nPozdJmpQ+tTy2xUknp8YVJnx/93dWXbRI6oGEwAVY26zWMcNPLtd8ekbPWbfSjUA=="
String privateKey = "MD4CAQAwEAYHKoZIzj0CAQYFK4EEAAoEJzAlAgEBBCA1IMt9uJOEdW7kB69aTDmSRdxbpESSDUhNd9/d8hM5lw=="
String data = "testtest"
String sign = Fx.crypto.ECC.sign(privateKey, data);
boolean verifySign = Fx.crypto.ECC.verifySign(publicKey, sign, data)
log.info(verifySign);4. verifySign ECC Signature Verification
ECC Signature Verification
ECCAPI.verifySign(<String publicKey>, <String sign>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| publicKey | String | Verification public key, generated using ECC algorithm, Base64 encoded, stored in X.509 standard format | Y |
| sign | String | Signed content | Y |
| data | String | Original content | Y |
Code examples
String publicKey = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEwGWFaJ9DfFEOerfs9ONP9nPozdJmpQ+tTy2xUknp8YVJnx/93dWXbRI6oGEwAVY26zWMcNPLtd8ekbPWbfSjUA=="
String privateKey = "MD4CAQAwEAYHKoZIzj0CAQYFK4EEAAoEJzAlAgEBBCA1IMt9uJOEdW7kB69aTDmSRdxbpESSDUhNd9/d8hM5lw=="
String data = "testtest"
String sign = Fx.crypto.ECC.sign(privateKey, data);
boolean verifySign = Fx.crypto.ECC.verifySign(publicKey, sign, data)
log.info(verifySign);Reference object com.fxiaoke.functions.api.RSAAPI
1. encrypt RSA encryption
RSA Encryption
RSAAPI.encrypt(<String publicKey>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| publicKey | String | Public key | Y |
| data | String | Data to be encrypted | Y |
Code examples
String publicKey =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyVTOYRGyEZ2gjY+N4bsH" +
"suSjy/WevRi5X7MXklwpcyHdIYGrw8si+PoGnGivMhL/tfmOAglAeVviF+QeebDs" +
"6kKXwHB/PacSgx82Q4yQFS2UNfLOG6WQNIlPHZ1094cDFlVdcjxCSYcvgoBLZaws" +
"GelKmnjk1cBUhleeZElKLPj7mF3yq4hehNewUv5W/eByUCZ0CUqnWFnKPJ/xUYqX" +
"Fuvqx20cNYKhjAPKgDcKbNBGCKJW2uu1MMyDrxr5MKkn5gsDZ/P7AI0yy4UVbQ5C" +
"qG4rfuAJZ/WZ7fx9PrGEUBYt0NX33tcXAO/denOwMp9N5HgJlJGlJzJ7esx/ex3K" +
"wwIDAQAB"
String originalContent = "testtest"
String text = Fx.crypto.RSA.encrypt(publicKey,originalContent)
log.info(text)
String privateKey =
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDJVM5hEbIRnaCN" +
"j43huwey5KPL9Z69GLlfsxeSXClzId0hgavDyyL4+gacaK8yEv+1+Y4CCUB5W+IX" +
"5B55sOzqQpfAcH89pxKDHzZDjJAVLZQ18s4bpZA0iU8dnXT3hwMWVV1yPEJJhy+C" +
"gEtlrCwZ6UqaeOTVwFSGV55kSUos+PuYXfKriF6E17BS/lb94HJQJnQJSqdYWco8" +
"n/FRipcW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+
"f2c9FvH9Td3LUsTsJ6hh5u5cHTw/ff7BhdfDyTEYJdyYc1IEfNjHPIX6QjHq3Zks" +
"V2EdRX2VbhEyU9uE1mMShSCqT7BYjScWFuabbpbl2EqDALtHQDfQluk640HmwN/U" +
"bD+a+4gQHfFC3bL976XqZpNV52bf+6zsmxI46MECgYA7auynp1+IUSrzF4sFtKfd" +
"YaPGn82p+PdDVKoA6hnjrIwnC5k6nR7XfSRyVt2n9myQYufoZs9WHwwme9FXEPYd" +
"qzJTqkMMtqh4jsGK1Uz95uUm3F0wZtvd0W17CrL9eR6My00oKXGcEMWJ+iGg7BSo" +
"JvxtK9uvc7rTlcbqxqD3dw==";
String decrypt = Fx.crypto.getRSA().decrypt(privateKey, text);
log.info(decrypt);//testtest2. decrypt RSA decryption
RSA Decryption
RSAAPI.decrypt(<String privateKey>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| privateKey | String | Private key | Y |
| data | String | Data to be decrypted | Y |
Code examples
String publicKey =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyVTOYRGyEZ2gjY+N4bsH" +
"suSjy/WevRi5X7MXklwpcyHdIYGrw8si+PoGnGivMhL/tfmOAglAeVviF+QeebDs" +
"6kKXwHB/PacSgx82Q4yQFS2UNfLOG6WQNIlPHZ1094cDFlVdcjxCSYcvgoBLZaws" +
"GelKmnjk1cBUhleeZElKLPj7mF3yq4hehNewUv5W/eByUCZ0CUqnWFnKPJ/xUYqX" +
"Fuvqx20cNYKhjAPKgDcKbNBGCKJW2uu1MMyDrxr5MKkn5gsDZ/P7AI0yy4UVbQ5C" +
"qG4rfuAJZ/WZ7fx9PrGEUBYt0NX33tcXAO/denOwMp9N5HgJlJGlJzJ7esx/ex3K" +
"wwIDAQAB"
String originalContent = "testtest"
String text = Fx.crypto.RSA.encrypt(publicKey,originalContent)
log.info(text)
String privateKey =
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwgg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z8pAU1deiUPAgIwR4ffbEgfhNQo1bf88lPhp" +
"+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 decrypt = Fx.crypto.getRSA().decrypt(privateKey, text);
log.info(decrypt);//testtest3. sign RSA signature
RSA Signature
RSAAPI.sign(<String algorithm>, <String privateKey>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| algorithm | String | RSA algorithm, mapping information: SHA1->SHA1WithRSA, SHA256->SHA256WithRSA, MD5->MD5withRSA | Y |
| privateKey | String | Private key | Y |
| data | String | Data to be signed | Y |
Code examples
String privateKey =
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDJVM5hEbIRnaCN" +
"j43huwey5KPL9Z69GLlfsxeSXClzId0hgavDyyL4+gacaK8yEv+1+Y4CCUB5W+IX" +
"5B55sOzqQpfAcH89pxKDHzZDjJAVLZQ18s4bpZA0iU8dnXT3hwMWVV1yPEJJhy+C" +
"gEtlrCwZ6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
"oQFQbp+g1109VhRcWMU5369bYNWOEFBOQPQU//7orF7gQB4XzHOAzShJAoGAcUj+" +
"f2c9FvH9Td3LUsTsJ6hh5u5cHTw/ff7BhdfDyTEYJdyYc1IEfNjHPIX6QjHq3Zks" +
"V2EdRX2VbhEyU9uE1mMShSCqT7BYjScWFuabbpbl2EqDALtHQDfQluk640HmwN/U" +
"bD+a+4gQHfFC3bL976XqZpNV52bf+6zsmxI46MECgYA7auynp1+IUSrzF4sFtKfd" +
"YaPGn82p+PdDVKoA6hnjrIwnC5k6nR7XfSRyVt2n9myQYufoZs9WHwwme9FXEPYd" +
"qzJTqkMMtqh4jsGK1Uz95uUm3F0wZtvd0W17CrL9eR6My00oKXGcEMWJ+iGg7BSo" +
"JvxtK9uvc7rTlcbqxqD3dw=="
String str = "testtest"
def sign = Fx.crypto.RSA.sign("SHA256",privateKey,str)
String publicKey =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyVTOYRGyEZ2gjY+N4bsH" +
"suSjy/WevRi5X7MXklwpcyHdIYGrw8si+PoGnGivMhL/tfmOAglAeVviF+QeebDs" +
"6kKXwHB/PacSgx82Q4yQFS2UNfLOG6WQNIlPHZ1094cDFlVdcjxCSYcvgoBLZaws" +
"GelKmnjk1cBUhleeZElKLPj7mF3yq4hehNewUv5W/eByUCZ0CUqnWFnKPJ/xUYqX" +
"Fuvqx20cNYKhjAPKgDcKbNBGCKJW2uu1MMyDrxr5MKkn5gsDZ/P7AI0yy4UVbQ5C" +
"qG4rfuAJZ/WZ7fx9PrGEUBYt0NX33tcXAO/denOwMp9N5HgJlJGlJzJ7esx/ex3K" +
"wwIDAQAB"
def ret = Fx.crypto.RSA.verifySign("SHA256", publicKey, sign, str)
log.info(ret)//true4. verifySign RSA signature verification
RSA Signature Verification
RSAAPI.verifySign(<String algorithm>, <String publicKey>, <String sign>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| algorithm | String | RSA algorithm with mapping: SHA1->SHA1WithRSA, SHA256->SHA256WithRSA, MD5->MD5withRSA | Y |
| publicKey | String | Public key | Y |
| sign | String | Signed content | Y |
| data | String | Original data | Y |
Code examples
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 str = "testtest"
def sign = Fx.crypto.RSA.sign("SHA256",privateKey,str)
String publicKey =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyVTOYRGyEZ2gjY+N4bsH" +
"suSjy/WevRi5X7MXklwpcyHdIYGrw8si+PoGnGivMhL/tfmOAglAeVviF+QeebDs" +
"6kKXwHB/PacSgx82Q4yQFS2UNfLOG6WQNIlPHZ1094cDFlVdcjxCSYcvgoBLZaws" +
"GelKmnjk1cBUhleeZElKLPj7mF3yq4hehNewUv5W/eByUCZ0CUqnWFnKPJ/xUYqX" +
"Fuvqx20cNYKhjAPKgDcKbNBGCKJW2uu1MMyDrxr5MKkn5gsDZ/P7AI0yy4UVbQ5C" +
"qG4rfuAJZ/WZ7fx9PrGEUBYt0NX33tcXAO/denOwMp9N5HgJlJGlJzJ7esx/ex3K" +
"wwIDAQAB"
def ret = Fx.crypto.RSA.verifySign("SHA256", publicKey, sign, str)
log.info(ret)//trueReference object com.fxiaoke.functions.api.HexAPI
1. encode Hex encoding
Hex Encoding
HexAPI.encode(<String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | String | Data to be encoded | Y |
Code examples
def str = 'testtest'
def encode = Fx.crypto.hex.encode(Strings.toUTF8Bytes(str))
log.info(encode) //7465737474657374
def decode = Fx.crypto.hex.decode(encode)
log.info(StringUtils.toUTF8String(decode)) //testtestNotice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
2. decode Hex encoding
Hex Encoding
HexAPI.decode(<String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| data | String | Data to be decoded | Y |
Code examples
def str = 'testtest'
def encode = Fx.crypto.hex.encode(Strings.toUTF8Bytes(str))
log.info(encode) //7465737474657374
def decode = Fx.crypto.hex.decode(encode)
log.info(StringUtils.toUTF8String(decode)) //testtestNotice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
Reference object com.fxiaoke.functions.api.HmacAPI
1. encrypt Hmac encryption
Hmac Encryption
HmacAPI.encrypt(<String algorithm>, <String secret>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| algorithm | String | Encryption algorithm. Supported algorithms: HmacMD5, HmacSHA1, HmacSHA256, HmacSHA384, HmacSHA512 | Y |
| secret | String | Secret key | Y |
| data | String | Data to be encrypted | Y |
Code examples
String algorithm = "HmacMD5"
String secret = 'secret'
String content = 'testtest'
byte[] data1 = Fx.crypto.hmac.encrypt(algorithm, secret, content)
byte[] data2 = Fx.crypto.hmac.encrypt(algorithm, secret.getBytes(), content)Notice
- Supported encryption algorithms: HmacMD5, HmacSHA1, HmacSHA256, HmacSHA384, HmacSHA512
- For encryption/decryption operations, if the parameter is of type byte[], special attention must be paid to whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
2. encrypt Hmac encryption
HMAC Encryption
HmacAPI.encrypt(<String algorithm>, <byte[] secret>, <String data>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| algorithm | String | Encryption algorithm. Supported algorithms: HmacMD5, HmacSHA1, HmacSHA256, HmacSHA384, HmacSHA512 | Y |
| secret | byte[] | Secret key | Y |
| data | String | Data to be encrypted | Y |
Code examples
String algorithm = "HmacMD5"
String secret = 'secret'
String content = 'testtest'
byte[] data1 = Fx.crypto.hmac.encrypt(algorithm, secret, content)
byte[] data2 = Fx.crypto.hmac.encrypt(algorithm, secret.getBytes(), content)Notice
- Supported encryption algorithms: HmacMD5, HmacSHA1, HmacSHA256, HmacSHA384, HmacSHA512
- When encrypting or decrypting data, if the parameter is of type byte[], pay attention to whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
Reference object com.fxiaoke.functions.api.SymmetryAPI
1. encrypt symmetric encryption, iv type is String
Symmetric encryption, iv type is String
SymmetryAPI.encrypt(<String algorithm>, <byte[] privateKey>, <byte[] data>, <byte[] iv>, <String mode>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| algorithm | String | Symmetric encryption algorithm. Supported algorithms: AES->AES/ECB/PKCS5Padding, DES->DES/ECB/PKCS5Padding, DESede->DESede/ECB/PKCS5Padding | Y |
| privateKey | byte[] | Private key with length of 16/24/32 bytes, corresponding to AES 128/192/256-bit key length | Y |
| data | byte[] | Data to be encrypted | Y |
| iv | byte[] | Optional parameter, initialization vector | -- |
| mode | String | Optional parameter, encryption and padding mode | -- |
Code examples
byte[] input = Strings.toUTF8Bytes("testtest")
byte[] key1 = Strings.toUTF8Bytes("1234567812345678") //Key length must be 16/24/32 bytes, corresponding to AES 128/192/256-bit key length
byte[] encrypt1 = Fx.crypto.symmetry.encrypt("AES", key1, input)
//Using specified IV + padding mode
byte[] encrypt2 = Fx.crypto.getSymmetry().encrypt("AES", key1, input, '1234567812345678', "AES/CBC/PKCS5Padding");
byte[] encrypt3 = Fx.crypto.getSymmetry().encrypt("AES", key1, input, '1234567812345678'.getBytes(), "AES/CBC/PKCS5Padding");Notice
- Supported encryption algorithms: AES\DES\3DES
- When encrypting or decrypting data, if the parameter is of type byte[], pay attention to whether the data is in Base64, Hex, or plain string format, as the conversion method to byte[] varies accordingly.
2. encrypt symmetric encryption, iv type is byte[]
Symmetric encryption, iv type is byte[]
SymmetryAPI.encrypt(<String algorithm>, <byte[] privateKey>, <byte[] data>, <String iv>, <String mode>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| algorithm | String | Symmetric encryption algorithm. Supported algorithms: AES->AES/ECB/PKCS5Padding, DES->DES/ECB/PKCS5Padding, DESede->DESede/ECB/PKCS5Padding | Y |
| privateKey | byte[] | Secret key with length of 16/24/32 bytes, corresponding to AES 128/192/256-bit key length | Y |
| data | byte[] | Data to be encrypted | Y |
| iv | String | Optional parameter, initialization vector | -- |
| mode | String | Optional parameter, encryption and padding mode | -- |
Code examples
byte[] input = Strings.toUTF8Bytes("testtest")
byte[] key1 = Strings.toUTF8Bytes("1234567812345678") //Key length must be 16/24/32 bytes, corresponding to AES 128/192/256-bit key length
byte[] encrypt1 = Fx.crypto.symmetry.encrypt("AES", key1, input)
//Using specified IV + padding mode
byte[] encrypt2 = Fx.crypto.getSymmetry().encrypt("AES", key1, input, '1234567812345678', "AES/CBC/PKCS5Padding");Notice
- When dealing with encryption and decryption data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] vary accordingly.
3. decrypt symmetric decryption, iv type is String
Symmetric decryption, iv type is String
SymmetryAPI.decrypt(<String algorithm>, <byte[] privateKey>, <byte[] data>, <String iv>, <String mode>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| algorithm | String | Symmetric encryption algorithm. Supported algorithms: AES->AES/ECB/PKCS5Padding, DES->DES/ECB/PKCS5Padding, DESede->DESede/ECB/PKCS5Padding | Y |
| privateKey | byte[] | Secret key with length of 16/24/32 bytes, corresponding to AES 128/192/256-bit key length | Y |
| data | byte[] | Data to be decrypted | Y |
| iv | String | Optional parameter, initialization vector | -- |
| mode | String | Optional parameter, encryption and padding mode | -- |
Code examples
byte[] input = Strings.toUTF8Bytes("Original content 12341")
String iv = "NIfb&95GUY86Gfgh"
String mode = "AES/CBC/PKCS5Padding"
byte[] key1 = Strings.toUTF8Bytes("1234567890abcdef") //Key, key length must be 16/24/32 bytes, corresponding to AES 128/192/256-bit key length
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))Notice
- When dealing with encryption and decryption data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
4. decrypt symmetric decryption, iv type is byte[]
Symmetric decryption, iv type is byte[]
SymmetryAPI.decrypt(<String algorithm>, <byte[] privateKey>, <byte[] data>, <byte[] iv>, <String mode>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| algorithm | String | Symmetric encryption algorithm. Supported algorithms: AES->AES/ECB/PKCS5Padding, DES->DES/ECB/PKCS5Padding, DESede->DESede/ECB/PKCS5Padding | Y |
| privateKey | byte[] | Secret key with length of 16/24/32 bytes, corresponding to AES 128/192/256-bit key length | Y |
| data | byte[] | Data to be decrypted | Y |
| iv | byte[] | Optional parameter, initialization vector | -- |
| mode | String | Optional parameter, encryption and padding mode | -- |
Code examples
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, key length must be 16/24/32 bytes, corresponding to AES 128/192/256-bit key length
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))Notice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
Reference object com.fxiaoke.functions.api.SM4API
1. encrypt SM4 encryption
SM4 Encryption
SM4API.encrypt(<String key>, <string data>, <String mode>, <String iv>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| key | String | Secret key | Y |
| data | string | Data to be encrypted | Y |
| mode | String | Encryption and padding mode | Y |
| iv | String | Optional parameter, initialization vector | Y |
Code examples
def key = "1234567812345678"
def data = "testtest"
def mode = "SM4/CBC/PKCS5Padding"
def iv = "1234567812345678" //16-bit
def encrypt = Fx.crypto.SM4.encrypt(key, data, mode, iv)
def decrypt = Fx.crypto.SM4.decrypt(key, encrypt, mode, iv)
log.info(StringUtils.toUTF8String(decrypt))//testtestNotice
- Supported encryption algorithms: AES\DES\3DES
- When encrypting or decrypting data, if the parameter is of type byte[], pay attention to whether the data is in Base64, Hex, or plain string format, as the conversion method to byte[] differs accordingly.
2. decrypt SM4 decryption
SM4 Decryption
SM4API.decrypt(<String key>, <byte data>, <String mode>, <String iv>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| key | String | Secret key | Y |
| data | byte | Data to be decrypted | Y |
| mode | String | Encryption and padding mode | Y |
| iv | String | Optional parameter, initialization vector | Y |
Code examples
def key = "1234567812345678"
def data = "testtest"
def mode = "SM4/CBC/PKCS5Padding"
def iv = "1234567812345678" //16-bit
def encrypt = Fx.crypto.SM4.encrypt(key, data, mode, iv)
def decrypt = Fx.crypto.SM4.decrypt(key, encrypt, mode, iv)
log.info(StringUtils.toUTF8String(decrypt))//testtestNotice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
Reference object com.fxiaoke.functions.api.SM2API
1. encode SM2 encryption
SM2 Encryption
SM2API.encode(<String input>, <byte pubKey>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| input | String | Data to be encrypted | Y |
| pubKey | byte | Public key for encryption (Hex format) | Y |
Code examples
def str = 'testtest'
def pubKey = "04e02df2e298eb9f1069905e6fd9f73bb74a2fe7c7d3a74952b7d3929a6ff7992f2d91e36ccb3c2b6a0860945ecfe68ffca181558e823280ab8fd9356893832c97"
String encode = Fx.crypto.getSM2().encode(str, pubKey);
log.debug(encode)//BMm7yAGdIYra3YFNftcqpP557b46CrqblXRxrXFHSv8AX1rc7UjqLQrWpZZfQeH/fViF/SLjPBqHAQCfVI1l3uV8M94F/IjxWqYhG01jXmyEGXUZ7hHrpMFyLhOUCZpJNkekHiQvRIdk
String decode = Fx.crypto.SM2.decode(encode, "2e8b0080a153226d5e01903def442677ba6667e15732334619d22a3591f1869c")
log.debug(decode)//testtestNotice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion method to byte[] varies accordingly.
2. decode SM2 decryption
SM2 Decryption
SM2API.decode(<String input>, <byte prvKey>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| input | String | Data to be decrypted (Base64 format) | Y |
| prvKey | byte | Encrypted private key (Hex format) | Y |
Code examples
def str = 'testtest'
def pubKey = "04e02df2e298eb9f1069905e6fd9f73bb74a2fe7c7d3a74952b7d3929a6ff7992f2d91e36ccb3c2b6a0860945ecfe68ffca181558e823280ab8fd9356893832c97"
String encode = Fx.crypto.getSM2().encode(str, pubKey);
log.debug(encode)//BMm7yAGdIYra3YFNftcqpP557b46CrqblXRxrXFHSv8AX1rc7UjqLQrWpZZfQeH/fViF/SLjPBqHAQCfVI1l3uV8M94F/IjxWqYhG01jXmyEGXUZ7hHrpMFyLhOUCZpJNkekHiQvRIdk
String decode = Fx.crypto.SM2.decode(encode, "2e8b0080a153226d5e01903def442677ba6667e15732334619d22a3591f1869c")
log.debug(decode)//testtestNotice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
3. sign SM2 signature
SM2 Signature
SM2API.sign(<String privteKey>, <String body>, <String mode>, <String userId>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| privteKey | String | Private key (Hex format) | Y |
| body | String | String to be signed | Y |
| mode | String | Signature algorithm mode | Y |
| userId | String | GM/T requirement: signer ID must be included | Y |
Code examples
def privteKey = '00a5c420b11eb7d6324ae2dcfee96e626d8f5e2e3ff9ae17d657ee3907803e33a6'
def str = 'test'
def mode = 'SM3withSM2' //Ciphertext (Hex format when mode is SM3withSM2, Base64 format when mode is SM2)
def userId = '1234567812345678'
//String Signed data (Hex format when mode is SM3withSM2, Base64 format when mode is SM2)
String sign = Fx.crypto.SM2.sign(privteKey, str, mode, userId)
log.debug(sign)
def publicKeyStr = '04483a5548e42bcac3bacaa1997ef26cfe9240c313fd570a613e8184f2a11af5f41107b75060778f93b422e396cf47926ccb1a149cdb516d89fdfe325605b3752d'
boolean success = Fx.crypto.SM2.verify(publicKeyStr, str, sign, mode, userId)
log.debug(success) //trueNotice
- Supported signing algorithms include SM3withSM2 and SM2.
- For encryption/decryption data, if the parameter is of type byte[], pay attention to whether the data is in Base64, Hex, or plain string format, as the conversion method to byte[] varies accordingly.
4. verify SM2 signature verification
SM2 Signature Verification
SM2API.verify(<String publicKeyStr>, <String body>, <String signatureStr>, <String mode>, <String userId>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| publicKeyStr | String | Public key (Hex format string) | Y |
| body | String | String to be signed | Y |
| signatureStr | String | Ciphertext (Hex format when mode is SM3withSM2, Base64 format when mode is SM2) | Y |
| mode | String | Signature algorithm mode | Y |
| userId | String | GM/T requirement: signer ID must be included | Y |
Code examples
def privteKey = '00a5c420b11eb7d6324ae2dcfee96e626d8f5e2e3ff9ae17d657ee3907803e33a6'
def str = 'test'
def mode = 'SM3withSM2' //Ciphertext (Hex format when mode is SM3withSM2, Base64 format when mode is SM2)
def userId = '1234567812345678'
//String Signed data (Hex format when mode is SM3withSM2, Base64 format when mode is SM2)
String sign = Fx.crypto.SM2.sign(privteKey, str, mode, userId)
log.debug(sign)
def publicKeyStr = '04483a5548e42bcac3bacaa1997ef26cfe9240c313fd570a613e8184f2a11af5f41107b75060778f93b422e396cf47926ccb1a149cdb516d89fdfe325605b3752d'
boolean success = Fx.crypto.SM2.verify(publicKeyStr, str, sign, mode, userId)
log.debug(success) //trueNotice
- Signature verification supports two modes: SM2 and SM3withSM2. The supported signing algorithms are SM3withSM2 and SM2.
- For encryption and decryption data, if the parameter is of type byte[], pay attention to whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
Reference object com.fxiaoke.functions.api.SM3API
1. encrypt sm3 signature
SM3 signature
SM3API.encrypt(<String str>, <String key>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| str | String | Data to be encrypted | Y |
| key | String | Secret key (optional parameter) | Y |
Code examples
def str = 'testtest'
String encrypt = Fx.crypto.SM3.encrypt("testtest")
log.debug(encrypt)//6cdfdbc1f5b70b1dd580db3b44ba12f3e0070d8eea439573fc9f22aaaf6a073c
boolean verify = Fx.crypto.SM3.verify("testtest", encrypt)
log.debug(verify)//trueNotice
- When encrypting or decrypting data, if the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
2. verify SM3 signature verification
SM3 signature verification
SM3API.verify(<String str>, <String hexString>, <String key>)
Request parameters
Request Body
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| str | String | Original data | Y |
| hexString | String | Encrypted data | Y |
| key | String | Secret key (optional parameter) | Y |
Code examples
def str = 'testtest'
String encrypt = Fx.crypto.SM3.encrypt("testtest")
log.debug(encrypt)//6cdfdbc1f5b70b1dd580db3b44ba12f3e0070d8eea439573fc9f22aaaf6a073c
boolean verify = Fx.crypto.SM3.verify("testtest", encrypt)
log.debug(verify)//trueNotice
- When dealing with encrypted or decrypted data where the parameter is of type byte[], it is important to note whether the data is in Base64, Hex, or plain string format, as the conversion methods to byte[] differ accordingly.
