dongle
English | 简体中文
Introduction
A simple, semantic and developer-friendly golang
package for encryption algorithms, has been included by awesome-go
Repository
github.com/dromara/dongle
gitee.com/dromara/dongle
gitcode.com/dromara/dongle
Installation
go get -u github.com/dromara/dongle
import (
"github.com/dromara/dongle"
)
go get -u gitee.com/dromara/dongle
import (
"gitee.com/dromara/dongle"
)
go get -u gitcode.com/dromara/dongle
import (
"gitcode.com/dromara/dongle"
)
Because dongle
was donated to the dromara organization, the repository url has changed. If the previous repository used was golang-module/dongle
, please replace the original repository with the new repository in go.mod
, for example
go mod edit -replace github.com/golang-module/dongle=github.com/dromara/dongle
Usage and example
Encode and decode
Encode and decode by hex
dongle.Encode.FromString("hello world").ByHex().ToString()
dongle.Decode.FromString("68656c6c6f20776f726c64").ByHex().ToString()
dongle.Encode.FromBytes([]byte("hello world")).ByHex().ToBytes()
dongle.Decode.FromBytes([]byte("68656c6c6f20776f726c64")).ByHex().ToBytes()
Encode and decode by base16
dongle.Encode.FromString("hello world").ByBase16().ToString()
dongle.Decode.FromString("68656c6c6f20776f726c64").ByBase16().ToString()
dongle.Encode.FromBytes([]byte("hello world")).ByBase16().ToBytes()
dongle.Decode.FromBytes([]byte("68656c6c6f20776f726c64")).ByBase16().ToBytes()
Encode and decode by base32
dongle.Encode.FromString("hello world").ByBase32().ToString()
dongle.Decode.FromString("NBSWY3DPEB3W64TMMQ======").ByBase32().ToString()
dongle.Encode.FromBytes([]byte("hello world")).ByBase32().ToBytes()
dongle.Decode.FromBytes([]byte("NBSWY3DPEB3W64TMMQ======")).ByBase32().ToBytes()
Encode and decode by base45
dongle.Encode.FromString("hello world").ByBase45().ToString()
dongle.Decode.FromString("+8D VD82EK4F.KEA2").ByBase45().ToString()
dongle.Encode.FromBytes([]byte("hello world")).ByBase45().ToBytes()
dongle.Decode.FromBytes([]byte("+8D VD82EK4F.KEA2")).ByBase45().ToBytes()
Encode and decode by base58
dongle.Encode.FromString("hello world").ByBase58().ToString()
dongle.Decode.FromString("StV1DL6CwTryKyV").ByBase58().ToString()
dongle.Encode.FromBytes([]byte("hello world")).ByBase58().ToBytes()
dongle.Decode.FromBytes([]byte("StV1DL6CwTryKyV")).ByBase58().ToBytes()
Encode and decode by base62
dongle.Encode.FromString("hello world").ByBase62().ToString()
dongle.Decode.FromString("AAwf93rvy4aWQVw").ByBase62().ToString()
dongle.Encode.FromBytes([]byte("hello world")).ByBase62().ToBytes()
dongle.Decode.FromBytes([]byte("AAwf93rvy4aWQVw")).ByBase62().ToBytes()
Encode and decode by base64
dongle.Encode.FromString("hello world").ByBase64().ToString()
dongle.Decode.FromString("aGVsbG8gd29ybGQ=").ByBase64().ToString()
dongle.Encode.FromBytes([]byte("hello world")).ByBase64().ToBytes()
dongle.Decode.FromBytes([]byte("aGVsbG8gd29ybGQ=")).ByBase64().ToBytes()
Encode and decode by base64URL
dongle.Encode.FromString("www.gouguoyin.cn").ByBase64URL().ToString()
dongle.Decode.FromString("d3d3LmdvdWd1b3lpbi5jbg==").ByBase64URL().ToString()
dongle.Encode.FromBytes([]byte("www.gouguoyin.cn")).ByBase64URL().ToBytes()
dongle.Decode.FromBytes([]byte("d3d3LmdvdWd1b3lpbi5jbg==")).ByBase64URL().ToBytes()
Encode and decode by base85
dongle.Encode.FromString("hello world").ByBase85().ToString()
dongle.Decode.FromString("BOu!rD]j7BEbo7").ByBase85().ToString()
dongle.Encode.FromBytes([]byte("hello world")).ByBase85().ToBytes()
dongle.Decode.FromBytes([]byte("BOu!rD]j7BEbo7")).ByBase85().ToBytes()
Encode and decode by base91
dongle.Encode.FromString("hello world").ByBase91().ToString()
dongle.Decode.FromString("TPwJh>Io2Tv!lE").ByBase91().ToString()
dongle.Encode.FromBytes([]byte("hello world")).ByBase91().ToBytes()
dongle.Decode.FromBytes([]byte("TPwJh>Io2Tv!lE")).ByBase91().ToBytes()
Encode and decode by base100
dongle.Encode.FromString("hello world").ByBase100().ToString()
dongle.Decode.FromString("TPwJh>Io2Tv!lE").ByBase100().ToString()
dongle.Encode.FromBytes([]byte("hello world")).ByBase100().ToBytes()
dongle.Decode.FromBytes([]byte("👟👜👣👣👦🐗👮👦👩👣👛")).ByBase100().ToBytes()
Encode and decode by safeURL
dongle.Encode.FromString("www.gouguoyin.cn?sex=男&age=18").BySafeURL().ToString()
dongle.Decode.FromString("www.gouguoyin.cn%3Fsex%3D%E7%94%B7%26age%3D18").BySafeURL().ToString()
dongle.Encode.FromBytes([]byte("www.gouguoyin.cn?sex=男&age=18")).BySafeURL().ToBytes()
dongle.Decode.FromBytes([]byte("www.gouguoyin.cn%3Fsex%3D%E7%94%B7%26age%3D18")).BySafeURL().ToBytes()
Encode and decode by morse
The default value of separator is /
dongle.Encode.FromString("dongle").ByMorse().ToString()
dongle.Decode.FromString("-../---/-./--./.-../.").ByMorse().ToString()
dongle.Encode.FromBytes([]byte("dongle")).ByMorse("|").ToBytes()
dongle.Decode.FromBytes([]byte("-..|---|-.|--.|.-..|.")).ByMorse("|").ToBytes()
Encrypt and decrypt
Encrypt by md2
dongle.Encrypt.FromString("hello world").ByMd2().ToHexString()
dongle.Encrypt.FromString("hello world").ByMd2().ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByMd2().ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByMd2().ToBase64Bytes()
Encrypt by md4
dongle.Encrypt.FromString("hello world").ByMd4().ToHexString()
dongle.Encrypt.FromString("hello world").ByMd4().ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByMd4().ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByMd4().ToBase64Bytes()
Encrypt by md5
dongle.Encrypt.FromString("hello world").ByMd5().ToHexString()
dongle.Encrypt.FromString("hello world").ByMd5().ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByMd5().ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByMd5().ToBase64Bytes()
Encrypt by sha1
dongle.Encrypt.FromString("hello world").BySha1().ToHexString()
dongle.Encrypt.FromString("hello world").BySha1().ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha1().ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha1().ToBase64Bytes()
Encrypt by sha3
include sha3-224, sha3-256, sha3-384, sha3-512
dongle.Encrypt.FromString("hello world").Sha3(224).ToHexString()
dongle.Encrypt.FromString("hello world").Sha3(224).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).Sha3(224).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).Sha3(224).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").Sha3(256).ToHexString()
dongle.Encrypt.FromString("hello world").Sha3(256).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).Sha3(256).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).Sha3(256).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").Sha3(384).ToHexString()
dongle.Encrypt.FromString("hello world").Sha3(384).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).Sha3(384).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).Sha3(384).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").Sha3(512).ToHexString()
dongle.Encrypt.FromString("hello world").Sha3(512).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).Sha3(512).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).Sha3(512).ToBase64Bytes()
Encrypt by sha224
dongle.Encrypt.FromString("hello world").BySha224().ToHexString()
dongle.Encrypt.FromString("hello world").BySha224().ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha224().ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha224().ToBase64Bytes()
Encrypt by sha256
dongle.Encrypt.FromString("hello world").BySha256().ToHexString()
dongle.Encrypt.FromString("hello world").BySha256().ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha256().ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha256().ToBase64Bytes()
Encrypt by sha384
dongle.Encrypt.FromString("hello world").BySha384().ToHexString()
dongle.Encrypt.FromString("hello world").BySha384().ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha384().ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha384().ToBase64Bytes()
Encrypt by sha512
include sha512, sha512-224, sha512-256
dongle.Encrypt.FromString("hello world").BySha512().ToHexBytes()
dongle.Encrypt.FromString("hello world").BySha512().ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha512().ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha512().ToBase64Bytes()
dongle.Encrypt.FromString("hello world").BySha512(224).ToHexBytes()
dongle.Encrypt.FromString("hello world").BySha512(224).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha512(224).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha512(224).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").BySha512(256).ToHexBytes()
dongle.Encrypt.FromString("hello world").BySha512(256).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha512(256).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).BySha512(256).ToBase64Bytes()
Encrypt by shake128
dongle.Encrypt.FromString("hello world").ByShake128(256).ToHexString()
dongle.Encrypt.FromString("hello world").ByShake128(256).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByShake128(256).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByShake128(256).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").ByShake128(512).ToHexString()
dongle.Encrypt.FromString("hello world").ByShake128(512).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByShake128(512).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByShake128(512).ToBase64Bytes()
Encrypt by shake256
dongle.Encrypt.FromString("hello world").ByShake256(384).ToHexString()
dongle.Encrypt.FromString("hello world").ByShake256(384).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByShake256(384).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByShake256(384).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").ByShake256(512).ToHexString()
dongle.Encrypt.FromString("hello world").ByShake256(512).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByShake256(512).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByShake256(512).ToBase64Bytes()
Encrypt by ripemd160
dongle.Encrypt.FromString("hello world").ByRipemd160().ToHexString()
dongle.Encrypt.FromString("hello world").ByRipemd160().ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByRipemd160().ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByRipemd160().ToBase64Bytes()
Encrypt by blake2b
include blake2b-256, blake2b-384, blake2b-512
dongle.Encrypt.FromString("hello world").ByBlake2b(256).ToHexBytes()
dongle.Encrypt.FromString("hello world").ByBlake2b(256).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByBlake2b(256).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByBlake2b(256).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").ByBlake2b(384).ToHexBytes()
dongle.Encrypt.FromString("hello world").ByBlake2b(384).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByBlake2b(384).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByBlake2b(384).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").ByBlake2b(512).ToHexBytes()
dongle.Encrypt.FromString("hello world").ByBlake2b(512).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByBlake2b(512).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByBlake2b(512).ToBase64Bytes()
Encrypt by blake2s
Currently, only blake2s-256 is supported
dongle.Encrypt.FromString("hello world").ByBlake2s(256).ToHexString()
dongle.Encrypt.FromString("hello world").ByBlake2s(256).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByBlake2s(256).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByBlake2s(256).ToBase64Bytes()
Encrypt by hmac-md2
dongle.Encrypt.FromString("hello world").ByHmacMd2("dongle").ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacMd2("dongle").ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacMd2([]byte("dongle")).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacMd2([]byte("dongle")).ToBase64Bytes()
Encrypt by hmac-md4
dongle.Encrypt.FromString("hello world").ByHmacMd4("dongle").ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacMd4("dongle").ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacMd4([]byte("dongle")).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacMd4([]byte("dongle")).ToBase64Bytes()
Encrypt by hmac-md5
dongle.Encrypt.FromString("hello world").ByHmacMd5("dongle").ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacMd5("dongle").ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacMd5([]byte("dongle")).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacMd5([]byte("dongle")).ToBase64Bytes()
Encrypt by hmac-sha1
dongle.Encrypt.FromString("hello world").ByHmacSha1("dongle").ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSha1("dongle").ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha1([]byte("dongle")).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha1([]byte("dongle")).ToBase64Bytes()
Encrypt by hmac-sha3
include hmac-sha3-224, hmac-sha3-256, hmac-sha3-384, hmac-sha3-512
dongle.Encrypt.FromString("hello world").ByHmacSha3("dongle", 224).ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSha3("dongle", 224).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha3([]byte("dongle"), 224).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha3([]byte("dongle"), 224).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").ByHmacSha3("dongle", 256).ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSha3("dongle", 256).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha3([]byte("dongle"), 256).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha3([]byte("dongle"), 256).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").ByHmacSha3("dongle", 384).ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSha3("dongle", 384).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha3([]byte("dongle"), 384).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha3([]byte("dongle"), 384).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").ByHmacSha3("dongle", 512).ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSha3("dongle", 512).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha3([]byte("dongle"), 512).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha3([]byte("dongle"), 512).ToBase64Bytes()
Encrypt by hmac-sha224
dongle.Encrypt.FromString("hello world").ByHmacSha224("dongle").ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSha224("dongle").ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha224([]byte("dongle")).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha224([]byte("dongle")).ToBase64Bytes()
Encrypt by hmac-sha256
dongle.Encrypt.FromString("hello world").ByHmacSha256("dongle").ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSha256("dongle").ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha256([]byte("dongle")).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha256([]byte("dongle")).ToBase64Bytes()
Encrypt by hmac-sha384
dongle.Encrypt.FromString("hello world").ByHmacSha384("dongle").ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSha384("dongle").ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha384([]byte("dongle")).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha384([]byte("dongle")).ToBase64Bytes()
Encrypt by hmac-sha512
include hmac-sha512, hmac-sha512-224, hmac-sha512-256
dongle.Encrypt.FromString("hello world").ByHmacSha512("dongle").ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSha512("dongle").ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha512([]byte("dongle")).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha512([]byte("dongle")).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").ByHmacSha512("dongle", 224).ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSha512("dongle", 224).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha512([]byte("dongle"), 224).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha512([]byte("dongle"), 224).ToBase64Bytes()
dongle.Encrypt.FromString("hello world").ByHmacSha512("dongle", 256).ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSha512("dongle", 256).ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha512([]byte("dongle"), 256).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSha512([]byte("dongle"), 256).ToBase64Bytes()
Encrypt by hmac-ripemd160
dongle.Encrypt.FromString("hello world").ByHmacRipemd160("dongle").ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacRipemd160("dongle").ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacRipemd160([]byte("dongle")).ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacRipemd160([]byte("dongle")).ToBase64Bytes()
Encrypt by hmac-sm3
dongle.Encrypt.FromString("hello world").ByHmacSm3().ToHexString()
dongle.Encrypt.FromString("hello world").ByHmacSm3().ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSm3().ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByHmacSm3().ToBase64Bytes()
Encrypt and decrypt by aes
cipher := dongle.NewCipher()
cipher.SetMode(dongle.CBC)
cipher.SetPadding(dongle.PKCS7)
cipher.SetKey("0123456789abcdef")
cipher.SetIV("0123456789abcdef")
rawString := dongle.Encrypt.FromString("hello world").ByAes(cipher).ToRawString()
dongle.Decrypt.FromRawString(rawString).ByAes(cipher).ToString()
dongle.Encrypt.FromString("hello world").ByAes(cipher).ToHexString()
dongle.Decrypt.FromHexString("c1e9b4529aac9793010f4677f6358efe").ByAes(cipher).ToString()
dongle.Encrypt.FromString("hello world").ByAes(cipher).ToBase64String()
dongle.Decrypt.FromBase64String("wem0Upqsl5MBD0Z39jWO/g==").ByAes(cipher).ToString()
rawBytes := dongle.Encrypt.FromBytes([]byte("hello world")).ByAes(cipher).ToRawBytes()
dongle.Decrypt.FromRawBytes(rawBytes)).ByAes(cipher).ToBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByAes(cipher).ToHexBytes()
dongle.Decrypt.FromHexBytes([]byte("c1e9b4529aac9793010f4677f6358efe")).ByAes(cipher).ToBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByAes(cipher).ToBase64Bytes()
dongle.Decrypt.FromBase64Bytes(()byte("wem0Upqsl5MBD0Z39jWO/g==")).ByAes(cipher).ToBytes()
Encrypt and decrypt by blowfish
cipher := dongle.NewCipher()
cipher.SetMode(dongle.CBC)
cipher.SetPadding(dongle.PKCS7)
cipher.SetKey("0123456789abcdef")
cipher.SetIV("12345678")
rawString := dongle.Encrypt.FromString("hello world").ByBlowfish(cipher).ToRawString()
dongle.Decrypt.FromRawString(rawString).ByBlowfish(cipher).ToString()
dongle.Encrypt.FromString("hello world").ByBlowfish(cipher).ToHexString()
dongle.Decrypt.FromHexString("c1e9b4529aac9793010f4677f6358efe").ByBlowfish(cipher).ToString()
dongle.Encrypt.FromString("hello world").ByBlowfish(cipher).ToBase64String()
dongle.Decrypt.FromBase64String("ksNyTXILWZgtIaq5p7ufQA==").ByBlowfish(cipher).ToString()
rawBytes := dongle.Encrypt.FromBytes([]byte("hello world")).ByBlowfish(cipher).ToRawBytes()
dongle.Decrypt.FromRawBytes(rawBytes).ByBlowfish(cipher).ToBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByBlowfish(cipher).ToHexBytes()
dongle.Decrypt.FromHexBytes([]byte("c1e9b4529aac9793010f4677f6358efe")).ByBlowfish(cipher).ToBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByBlowfish(cipher).ToBase64Bytes()
dongle.Decrypt.FromBase64Bytes(()byte("ksNyTXILWZgtIaq5p7ufQA==")).ByBlowfish(cipher).ToBytes()
Encrypt and decrypt by des
cipher := dongle.NewCipher()
cipher.SetMode(dongle.CBC)
cipher.SetPadding(dongle.PKCS7)
cipher.SetKey("12345678")
cipher.SetIV("12345678")
rawString := dongle.Encrypt.FromString("hello world").ByDes(cipher).ToRawString()
dongle.Decrypt.FromRawString(rawString).ByDes(cipher).ToString()
dongle.Encrypt.FromString("hello world").ByDes(cipher).ToHexString()
dongle.Decrypt.FromHexString("0b2a92e81fb49ce1a43266aacaea7b81").ByDes(cipher).ToString()
dongle.Encrypt.FromString("hello world").ByDes(cipher).ToBase64String()
dongle.Decrypt.FromBase64String("CyqS6B+0nOGkMmaqyup7gQ==").ByDes(cipher).ToString()
rawBytes := dongle.Encrypt.FromBytes([]byte("hello world")).ByDes(cipher).ToRawBytes()
dongle.Decrypt.FromRawBytes(rawBytes).ByDes(cipher).ToBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByDes(cipher).ToHexBytes()
dongle.Decrypt.FromHexBytes([]byte("0b2a92e81fb49ce1a43266aacaea7b81")).ByDes(cipher).ToBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByDes(cipher).ToBase64Bytes()
dongle.Decrypt.FromBase64Bytes(()byte("CyqS6B+0nOGkMmaqyup7gQ==")).ByDes(cipher).ToBytes()
Encrypt and decrypt by 3des
cipher := dongle.NewCipher()
cipher.SetMode(dongle.CBC)
cipher.SetPadding(dongle.PKCS7)
cipher.SetKey("123456781234567812345678")
cipher.SetIV("12345678")
rawString := dongle.Encrypt.FromString("hello world").By3Des(cipher).ToRawString()
dongle.Decrypt.FromRawString(rawString).By3Des(cipher).ToString()
dongle.Encrypt.FromString("hello world").By3Des(cipher).ToHexString()
dongle.Decrypt.FromHexString("0b2a92e81fb49ce1a43266aacaea7b81").By3Des(cipher).ToString()
dongle.Encrypt.FromString("hello world").By3Des(cipher).ToBase64String()
dongle.Decrypt.FromBase64String("CyqS6B+0nOGkMmaqyup7gQ==").By3Des(cipher).ToString()
rawBytes := dongle.Encrypt.FromBytes([]byte("hello world")).By3Des(cipher).ToRawBytes()
dongle.Decrypt.FromRawBytes(rawBytes).By3Des(cipher).ToBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).By3Des(cipher).ToHexBytes()
dongle.Decrypt.FromHexBytes([]byte("0b2a92e81fb49ce1a43266aacaea7b81")).By3Des(cipher).ToBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).By3Des(cipher).ToBase64Bytes()
dongle.Decrypt.FromBase64Bytes(()byte("CyqS6B+0nOGkMmaqyup7gQ==")).By3Des(cipher).ToBytes()
Encrypt and decrypt by rsa
pkcs1PublicKey := `-----BEGIN RSA PUBLIC KEY-----
MIGJAoGBAK12MTd84qkCZzp4iLUj8YSUglaFMsFlv9KlIL4+Xts40PK3+wbsXPEw
cujGeUmdgMeZiK7SLLSz8QeE0v7Vs+cGK4Bs4qLtMGCiO6wEuyt10KsafTyBktFn
dk/+gBLr7B/b+9+HaMIIoJUdsFksdAg3cxTSpwVApe98loFNRfqDAgMBAAE=
-----END RSA PUBLIC KEY-----`
pkcs1PrivateKey := `-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCtdjE3fOKpAmc6eIi1I/GElIJWhTLBZb/SpSC+Pl7bONDyt/sG
7FzxMHLoxnlJnYDHmYiu0iy0s/EHhNL+1bPnBiuAbOKi7TBgojusBLsrddCrGn08
gZLRZ3ZP/oAS6+wf2/vfh2jCCKCVHbBZLHQIN3MU0qcFQKXvfJaBTUX6gwIDAQAB
AoGAFwAfEo56t5JcAcLNzccQVVYj2jkbO820G8hNiSxYA5WLD0QaAxcAU/Lqqbb3
ii1aUB0ppJS13NgnU6nnGGdZzUYBG1Hai6EkVyCGrI4amQ93AaVdKncL8gJ4RZAm
YzPPUwSMEESsu24pS1NF1G1Y8C+28b/Wr0oqOsCvL6PhsMECQQDwsPJJoWRx7ZJw
E1K5KLT0cXKyrIpyXY3I6tyA5imCzOzccf3d1vDgB0L9sdSO7bG3ceSwpAeiWEbg
5jGZemPzAkEAuH6U4pEI4AMbWnatpK55Rc235NDgmT3VyIuRaKC02YXAZ+jznFep
XMd4DTli4R9r3j2YVhUpyDVbdQpFH98DMQJAQpOvcU6DSkA80WOG7lCkPTlkUKgJ
Y7kdDwZoF/+SW+vzWMbvQf3CgzV/Ak2+TgrRrbyDVZkJw45HjM4fyiRgoQJBALH/
/qlxgPyQQs3O/s2KQBsm1auAE5IF5MLuVUZ69sF/mBko2hEXSqHnGV645TuKU0pC
Zz12ga9WO3z6gaK0SaECQQDah1pKt9ViBBy4USXK3OWXEloHuTwmyr9AbLqqI5tQ
2eNuH0NkuJYQmnXmHLbKOELoYocldEBXmkzPXSN+X9kV
-----END RSA PRIVATE KEY-----`
pkcs8PublicKey := `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqzZNa9VrcewyU6wDoV7Y9kAHq
X1VK0B3Rb6GNmQe4zLEfce7cVTaLrc4VGTKl35tADG1cRHqtaG4S/WttpiGZBhxJ
y4MpOXb6eIPiVLsn2lL+rJo5XdbSr3gyjxEOQQ97ihtw4lDd5wMo4bIOuw1LtMez
HC1outlM6x+/BB0BSQIDAQAB
-----END PUBLIC KEY-----`
pkcs8PrivateKey := `-----BEGIN PRIVATE KEY-----
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKrNk1r1Wtx7DJTr
AOhXtj2QAepfVUrQHdFvoY2ZB7jMsR9x7txVNoutzhUZMqXfm0AMbVxEeq1obhL9
a22mIZkGHEnLgyk5dvp4g+JUuyfaUv6smjld1tKveDKPEQ5BD3uKG3DiUN3nAyjh
sg67DUu0x7McLWi62UzrH78EHQFJAgMBAAECgYAeo3nHWzPNURVUsUMcan96U5bE
YA2AugxfQVMNf2HvOGidZ2adh3udWrQY/MglERNcTd5gKriG2rDEH0liBecIrNKs
BL4lV+qHEGRUcnDDdtUBdGInEU8lve5keDgmX+/huXSRJ+3tYA5u9j+32RquVczv
Idtb5XnBLUl61k0osQJBAON5+eJjtw6xpn+pveU92BSHvaJYVyrLHwUjR07aNKb7
GlGVM3MGf1FCa8WQUo9uUzYxGLtg5Qf3sqwOrwPd5UsCQQDAOF/zWqGuY3HfV/1w
giXiWp8rc+S8tanMj5M37QQbYW5YLjUmJImoklVahv3qlgLZdEN5ZSueM5jfoSFt
Nts7AkBKoRDvSiGbi4MBbTHkzLZgfewkH/FxE7S4nctePk553fXTgCyh9ya8BRuQ
dHnxnpNkOxVPHEnnpEcVFbgrf5gjAkB7KmRI4VTiEfRgINhTJAG0VU7SH/N7+4cu
fPzfA+7ywG5c8Fa79wOB0SoB1KeUjcSLo5Ssj2fwea1F9dAeU90LAkBJQFofveaD
a3YlN4EQZOcCvJKmg7xwWuGxFVTZDVVEws7UCQbEOEEXZrNd9x0IF5kpPLR+rxua
RPgUNaDGIh5o
-----END PRIVATE KEY-----`
1.RSA encrypt by public key and decrypt by private key
cipherText := dongle.Encrypt.FromString("hello world").ByRsa(pkcs1PublicKey)
dongle.Decrypt.FromHexString(cipherText.ToHexString()).ByRsa(pkcs1PrivateKey).ToString()
dongle.Decrypt.FromBase64String(cipherText.ToBase64String()).ByRsa(pkcs1PrivateKey).ToString()
cipherText := dongle.Encrypt.FromBytes([]byte("hello world")).ByRsa([]byte(pkcs1PublicKey))
dongle.Decrypt.FromHexBytes(cipherText.ToHexBytes()).ByRsa([]byte(pkcs1PrivateKey)).ToByte()
dongle.Decrypt.FromBase64Bytes(cipherText.ToBase64Bytes()).ByRsa([]byte(pkcs1PrivateKey)).ToByte()
cipherText := dongle.Encrypt.FromString("hello world").ByRsa(pkcs8PublicKey)
dongle.Decrypt.FromHexString(cipherText.ToHexString()).ByRsa(pkcs8PrivateKey).ToString()
dongle.Decrypt.FromBase64String(cipherText.ToBase64String()).ByRsa(pkcs8PrivateKey).ToString()
cipherText := dongle.Encrypt.FromBytes([]byte("hello world")).ByRsa([]byte(pkcs8PublicKey))
dongle.Decrypt.FromHexBytes(cipherText.ToHexBytes()).ByRsa(pkcs8PrivateKey).ToByte()
dongle.Decrypt.FromBase64Bytes(cipherText.ToBase64Bytes()).ByRsa(pkcs8PrivateKey).ToByte()
2.RSA encrypt by private key and decrypt by public key
cipherText := dongle.Encrypt.FromString("hello world").ByRsa(pkcs1PrivateKey)
dongle.Decrypt.FromHexString(cipherText.ToHexString()).ByRsa(pkcs1PublicKey).ToString()
dongle.Decrypt.FromBase64String(cipherText.ToBase64String()).ByRsa(pkcs1PublicKey).ToString()
cipherText := dongle.Encrypt.FromBytes([]byte("hello world")).ByRsa([]byte(pkcs1PrivateKey))
dongle.Decrypt.FromHexBytes(cipherText.ToHexBytes()).ByRsa([]byte(pkcs1PublicKey)).ToByte()
dongle.Decrypt.FromBase64Bytes(cipherText.ToBase64Bytes()).ByRsa([]byte(pkcs1PublicKey)).ToByte()
cipherText := dongle.Encrypt.FromString("hello world").ByRsa(pkcs8PrivateKey)
dongle.Decrypt.FromHexString(cipherText.ToHexString()).ByRsa(pkcs8PublicKey).ToString()
dongle.Decrypt.FromBase64String(cipherText.ToBase64String()).ByRsa(pkcs8PublicKey).ToString()
cipherText := dongle.Encrypt.FromBytes([]byte("hello world")).ByRsa([]byte(pkcs8PrivateKey))
dongle.Decrypt.FromHexBytes(cipherText.ToHexBytes()).ByRsa(pkcs8PublicKey).ToByte()
dongle.Decrypt.FromBase64Bytes(cipherText.ToBase64Bytes()).ByRsa(pkcs8PublicKey).ToByte()
Encrypt and decrypt by tea
If plaintext more than 8 bytes, block encryption with empty string padding. Rounds must be even, the default value is 64
dongle.Encrypt.FromString("hello world").ByTea("0123456789abcdef").ToHexString()
dongle.Decrypt.FromHexString("bfa8d956247c0dcecfe2b0ef44b08aab").ByTea("0123456789abcdef").ToString()
dongle.Encrypt.FromString("hello world").ByTea("0123456789abcdef").ToBase64String()
dongle.Decrypt.FromBase64String("v6jZViR8Dc7P4rDvRLCKqw==").ByTea("0123456789abcdef").ToString()
dongle.Encrypt.FromBytes([]byte("hello world")).ByTea("0123456789abcdef", 32).ToHexBytes()
dongle.Decrypt.FromHexBytes([]byte("bfa8d956247c0dcecfe2b0ef44b08aab")).ByTea("4539658173a59fc2", 64).ToBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByTea("0123456789abcdef", 32).ToBase64Bytes()
dongle.Decrypt.FromBase64Bytes(()byte("v6jZViR8Dc7P4rDvRLCKqw==")).ByTea("0123456789abcdef", 64).ToBytes()
Encrypt and decrypt by rc4
dongle.Encrypt.FromString("hello world").ByRc4("dongle").ToHexString()
dongle.Encrypt.FromHexString("eba154b4cb5a9038dbbf9d").ByRc4("dongle").ToString()
dongle.Encrypt.FromString("hello world").ByRc4("dongle").ToBase64String()
dongle.Decrypt.FromBase64String("66FUtMtakDjbv50=").ByRc4("dongle").ToString()
dongle.Encrypt.FromBytes([]byte("hello world")).ByRc4("dongle").ToHexBytes()
dongle.Decrypt.FromBase64Bytes([]byte("hello world")).ByRc4("dongle").ToBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).ByRc4("dongle").ToBase64Bytes()
dongle.Decrypt.FromBase64Bytes([]byte("66FUtMtakDjbv50=")).ByRc4("dongle").ToBytes()
Encrypt by sm3
dongle.Encrypt.FromString("hello world").BySm3().ToHexString()
dongle.Encrypt.FromString("hello world").BySm3().ToBase64String()
dongle.Encrypt.FromBytes([]byte("hello world")).BySm3().ToHexBytes()
dongle.Encrypt.FromBytes([]byte("hello world")).BySm3().ToBase64Bytes()
Sign and verify
Bcrypt sign and verify
Rounds allowed range is 4 to 31, the default value is 10
sign := dongle.Sign.FromString("hello world").ByBcrypt()
dongle.Verify.FromRawString(sign.ToRawString(), "hello world").ByBcrypt().ToBool()
sign := dongle.Sign.FromBytes([]byte("hello world")).ByBcrypt(10)
dongle.Verify.FromRawBytes([]byte(sign.ToRawBytes()), []byte("hello world")).ByBcrypt(10).ToBool()
Ed25519 sign and verify
var publicKey, privateKey []byte
publicKey, privateKey, _ = ed25519.GenerateKey(nil)
hexPublicKey := dongle.Encode.FromBytes(publicKey).ByHex().ToBytes()
hexPrivateKey := dongle.Encode.FromBytes(privateKey).ByHex().ToBytes()
base64PublicKey := dongle.Encode.FromBytes(publicKey).ByBase64().ToBytes()
base64PrivateKey := dongle.Encode.FromBytes(privateKey).ByBase64().ToBytes()
sign := dongle.Sign.FromString("hello world").ByEd25519(privateKey, dongle.Raw)
dongle.Verify.FromRawString(sign.ToRawString(), "hello world").ByEd25519(publicKey, dongle.Raw).ToBool()
dongle.Verify.FromHexString(sign.ToHexString(), "hello world").ByEd25519(publicKey, dongle.Raw).ToBool()
dongle.Verify.FromBase64String(sign.ToBase64String(), "hello world").ByEd25519(publicKey, dongle.Raw).ToBool()
sign := dongle.Sign.FromString("hello world").ByEd25519(hexPrivateKey, dongle.Hex)
dongle.Verify.FromRawString(sign.ToRawString(), "hello world").ByEd25519(hexPublicKey, dongle.Hex).ToBool()
dongle.Verify.FromHexString(sign.ToHexString(), "hello world").ByEd25519(hexPublicKey, dongle.Hex).ToBool()
dongle.Verify.FromBase64String(sign.ToBase64String(), "hello world").ByEd25519(hexPublicKey, dongle.Hex).ToBool()
sign := dongle.Sign.FromString("hello world").ByEd25519(base64PrivateKey, dongle.Base64)
dongle.Verify.FromRawString(sign.ToRawString(), "hello world").ByEd25519(base64PublicKey, dongle.Base64).ToBool()
dongle.Verify.FromHexString(sign.ToHexString(), "hello world").ByEd25519(base64PublicKey, dongle.Base64).ToBool()
dongle.Verify.FromBase64String(sign.ToBase64String(), "hello world").ByEd25519(base64PublicKey, dongle.Base64).ToBool()
Rsa sign and verify
Hash algorithm only supports MD5, SHA1, SHA224, SHA256, SHA384, SHA512, RIPEMD160
pkcs1PublicKey := `-----BEGIN RSA PUBLIC KEY-----
MIGJAoGBAK12MTd84qkCZzp4iLUj8YSUglaFMsFlv9KlIL4+Xts40PK3+wbsXPEw
cujGeUmdgMeZiK7SLLSz8QeE0v7Vs+cGK4Bs4qLtMGCiO6wEuyt10KsafTyBktFn
dk/+gBLr7B/b+9+HaMIIoJUdsFksdAg3cxTSpwVApe98loFNRfqDAgMBAAE=
-----END RSA PUBLIC KEY-----`
pkcs1PrivateKey := `-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCtdjE3fOKpAmc6eIi1I/GElIJWhTLBZb/SpSC+Pl7bONDyt/sG
7FzxMHLoxnlJnYDHmYiu0iy0s/EHhNL+1bPnBiuAbOKi7TBgojusBLsrddCrGn08
gZLRZ3ZP/oAS6+wf2/vfh2jCCKCVHbBZLHQIN3MU0qcFQKXvfJaBTUX6gwIDAQAB
AoGAFwAfEo56t5JcAcLNzccQVVYj2jkbO820G8hNiSxYA5WLD0QaAxcAU/Lqqbb3
ii1aUB0ppJS13NgnU6nnGGdZzUYBG1Hai6EkVyCGrI4amQ93AaVdKncL8gJ4RZAm
YzPPUwSMEESsu24pS1NF1G1Y8C+28b/Wr0oqOsCvL6PhsMECQQDwsPJJoWRx7ZJw
E1K5KLT0cXKyrIpyXY3I6tyA5imCzOzccf3d1vDgB0L9sdSO7bG3ceSwpAeiWEbg
5jGZemPzAkEAuH6U4pEI4AMbWnatpK55Rc235NDgmT3VyIuRaKC02YXAZ+jznFep
XMd4DTli4R9r3j2YVhUpyDVbdQpFH98DMQJAQpOvcU6DSkA80WOG7lCkPTlkUKgJ
Y7kdDwZoF/+SW+vzWMbvQf3CgzV/Ak2+TgrRrbyDVZkJw45HjM4fyiRgoQJBALH/
/qlxgPyQQs3O/s2KQBsm1auAE5IF5MLuVUZ69sF/mBko2hEXSqHnGV645TuKU0pC
Zz12ga9WO3z6gaK0SaECQQDah1pKt9ViBBy4USXK3OWXEloHuTwmyr9AbLqqI5tQ
2eNuH0NkuJYQmnXmHLbKOELoYocldEBXmkzPXSN+X9kV
-----END RSA PRIVATE KEY-----`
pkcs8PublicKey := `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqzZNa9VrcewyU6wDoV7Y9kAHq
X1VK0B3Rb6GNmQe4zLEfce7cVTaLrc4VGTKl35tADG1cRHqtaG4S/WttpiGZBhxJ
y4MpOXb6eIPiVLsn2lL+rJo5XdbSr3gyjxEOQQ97ihtw4lDd5wMo4bIOuw1LtMez
HC1outlM6x+/BB0BSQIDAQAB
-----END PUBLIC KEY-----`
pkcs8PrivateKey := `-----BEGIN PRIVATE KEY-----
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKrNk1r1Wtx7DJTr
AOhXtj2QAepfVUrQHdFvoY2ZB7jMsR9x7txVNoutzhUZMqXfm0AMbVxEeq1obhL9
a22mIZkGHEnLgyk5dvp4g+JUuyfaUv6smjld1tKveDKPEQ5BD3uKG3DiUN3nAyjh
sg67DUu0x7McLWi62UzrH78EHQFJAgMBAAECgYAeo3nHWzPNURVUsUMcan96U5bE
YA2AugxfQVMNf2HvOGidZ2adh3udWrQY/MglERNcTd5gKriG2rDEH0liBecIrNKs
BL4lV+qHEGRUcnDDdtUBdGInEU8lve5keDgmX+/huXSRJ+3tYA5u9j+32RquVczv
Idtb5XnBLUl61k0osQJBAON5+eJjtw6xpn+pveU92BSHvaJYVyrLHwUjR07aNKb7
GlGVM3MGf1FCa8WQUo9uUzYxGLtg5Qf3sqwOrwPd5UsCQQDAOF/zWqGuY3HfV/1w
giXiWp8rc+S8tanMj5M37QQbYW5YLjUmJImoklVahv3qlgLZdEN5ZSueM5jfoSFt
Nts7AkBKoRDvSiGbi4MBbTHkzLZgfewkH/FxE7S4nctePk553fXTgCyh9ya8BRuQ
dHnxnpNkOxVPHEnnpEcVFbgrf5gjAkB7KmRI4VTiEfRgINhTJAG0VU7SH/N7+4cu
fPzfA+7ywG5c8Fa79wOB0SoB1KeUjcSLo5Ssj2fwea1F9dAeU90LAkBJQFofveaD
a3YlN4EQZOcCvJKmg7xwWuGxFVTZDVVEws7UCQbEOEEXZrNd9x0IF5kpPLR+rxua
RPgUNaDGIh5o
-----END PRIVATE KEY-----`
sign := dongle.Sign.FromString("hello world").ByRsa(pkcs1PrivateKey, dongle.MD5)
dongle.Verify.FromRawString(sign.ToRawString(), "hello world").ByRsa(pkcs1PublicKey, dongle.MD5).ToBool()
dongle.Verify.FromHexString(sign.ToHexString(), "hello world").ByRsa(pkcs1PublicKey, dongle.MD5).ToBool()
dongle.Verify.FromBase64String(sign.ToBase64String(), "hello world").ByRsa(pkcs1PublicKey, dongle.MD5).ToBool()
sign := dongle.Sign.FromBytes([]byte("hello world")).ByRsa([]byte(pkcs8PrivateKey), dongle.SHA512).ToRawBytes()
dongle.Verify.FromRawBytes(sign.ToRawBytes(), []byte("hello world")).ByRsa([]byte(pkcs1PublicKey), dongle.SHA512).ToBool()
dongle.Verify.FromHexBytes(sign.ToHexBytes(), []byte("hello world")).ByRsa([]byte(pkcs1PublicKey), dongle.SHA512).ToBool()
dongle.Verify.FromBase64Bytes(sign.ToBase64Bytes(), []byte("hello world")).ByRsa([]byte(pkcs1PublicKey), dongle.SHA512).ToBool()
OpenSSL
RSA key
publicKey, privateKey := openssl.RSA.GenKeyPair(opensssl.PKCS1, 1024)
publicKey, privateKey := openssl.RSA.GenKeyPair(opensssl.PKCS8, 2048)
openssl.RSA.VerifyKeyPair(publicKey, privateKey)
openssl.RSA.VerifyKeyPair(publicKey, []byte("xxx"))
openssl.RSA.IsPublicKey(publicKey)
openssl.RSA.IsPublicKey(privateKey)
openssl.RSA.IsPrivateKey(privateKey)
openssl.RSA.IsPrivateKey(publicKey)
pub, err := openssl.RSA.ParsePublicKey(publicKey)
pri, err := openssl.RSA.ParsePrivateKey(privateKey)
openssl.RSA.FormatPublicKey(openssl.PKCS1, publicKey1)
openssl.RSA.FormatPublicKey(openssl.PKCS8, publicKey8)
openssl.RSA.FormatPrivateKey(openssl.PKCS1, privateKey1)
openssl.RSA.FormatPrivateKey(openssl.PKCS8, privateKey8)
keyBytes, err := openssl.RSA.CompressKey(key)
publicKey, err := openssl.RSA.ExportPublicKey(privateKey)
Error handling
If more than one error occurs, only the first error is returned
e := dongle.Encrypt.FromString("hello world").ByRsa("xxxx")
if e.Error != nil {
log.Fatal(e.Error)
}
fmt.Println(e.ToString())
rsa: invalid public key, please make sure the public key is valid
Feature list
References
Online website
Dongle
is a non-commercial open source project. If you want to support Dongle
, you can buy a cup of coffee for developer.
Thanks
Dongle
had been being developed with GoLand under the free JetBrains Open Source license, I would like to express my thanks here.