Documentation
¶
Index ¶
- func BlockDecrypt(block cipher.Block, mode BlockStreamMode, value []byte) ([]byte, error)
- func BlockEncrypt(block cipher.Block, mode BlockStreamMode, value []byte) ([]byte, error)
- func DecodePemHexBase64(data []byte) ([]byte, error)
- func DecryptByAesCBC(encrypted, key, iv []byte) (decrypted []byte, err error)
- func DecryptByAesCTR(origData, key []byte) (encrypted []byte, err error)
- func DecryptByRSA(privateKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error)
- func DecryptByRSABytes(privateKey []byte, ciphertext []byte) ([]byte, error)
- func DecryptBySM2(privateKey *sm2.PrivateKey, ciphertext []byte) ([]byte, error)
- func DecryptBySM2Bytes(privateKey []byte, ciphertext []byte) (text []byte, err error)
- func EncryptByAesCBC(origData, key, iv []byte) (encrypted []byte, err error)
- func EncryptByAesCTR(origData, key []byte) (encrypted []byte, err error)
- func EncryptByRSA(publicKey *rsa.PublicKey, content []byte) ([]byte, error)
- func EncryptByRSABytes(publicKey, content []byte) ([]byte, error)
- func GenerateBase64Key(secretLength core.SecretKeyLengthType, secretFormat core.SecretKeyFormatType) (pkStr, pbkStr string, err error)
- func GenerateECDSAKey(privateWriter, publicWriter io.Writer, c elliptic.Curve) error
- func GenerateECDSAKeyToMemory(c elliptic.Curve) (privateBytes []byte, publicBytes []byte, err error)
- func GenerateRSAKey(privateWriter, publicWriter io.Writer, bits RSABit) error
- func GenerateRSAKeyToMemory(bits RSABit) (privateBytes []byte, publicBytes []byte, err error)
- func GenerateSSHKey(bits RSABit) (pkBytes []byte, pbkBytes []byte, err error)
- func HMacMD5(data []byte, salt ...[]byte) string
- func HMacSha256(key []byte, value []byte) string
- func MD5(str []byte, salt ...[]byte) string
- func ParseRsaPrivateKey(derBytes []byte) (privateKey *rsa.PrivateKey, err error)
- func ParseRsaPublicKey(derBytes []byte) (publicKey *rsa.PublicKey, err error)
- func ParseSM2PublicKey(derBytes []byte) (publicKey *sm2.PublicKey, err error)
- func RsaPrivateDecrypt(privateKeyBytes, cipherBytes []byte) (textBytes []byte, err error)
- func RsaPublicEncrypt(publicKeyBytes, textBytes []byte) ([]byte, error)
- func SM2PublicEncrypt(publicKeyBytes, textBytes []byte) ([]byte, error)
- func SignByRSA(key *rsa.PrivateKey, licenseBytes []byte) (license string, err error)
- func SignByRSABytes(key, licenseBytes []byte) (string, error)
- func SignBySM2(privateKey *sm2.PrivateKey, licenseBytes []byte) (license string, err error)
- func SignBySM2Bytes(privateKey, licenseBytes []byte) (license string, err error)
- func VerifyByRSA(publicKeyBase64, licenseCode string) (license string, valid bool, err error)
- func VerifyBySM2(publicKeyBase64, licenseCode string) (license string, valid bool, err error)
- type BlockStreamMode
- type RSABit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlockDecrypt ¶
func BlockEncrypt ¶
func DecodePemHexBase64 ¶
DecodePemHexBase64 解析pem或者hex或者base64编码成der编码.
func DecryptByAesCBC ¶
DecryptByAesCBC cbc模式解密.
func DecryptByAesCTR ¶
func DecryptByRSA ¶
func DecryptByRSA(privateKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error)
DecryptByRSA 使用RSA私钥解密.
func DecryptByRSABytes ¶
DecryptByRSABytes 使用RSA私钥解密.
func DecryptBySM2 ¶
func DecryptBySM2(privateKey *sm2.PrivateKey, ciphertext []byte) ([]byte, error)
DecryptBySM2 使用SM2私钥解密.
func DecryptBySM2Bytes ¶
func EncryptByAesCBC ¶
EncryptByAesCBC 加密 AES-128 key长度:16, 24, 32 bytes 对应 AES-128, AES-192, AES-256. CBC比EBC更安全,但不可并行.
func EncryptByAesCTR ¶
func EncryptByRSA ¶
EncryptByRSA 使用RSA公钥加密.
func EncryptByRSABytes ¶
EncryptByRSABytes 使用RSA公钥加密.
func GenerateBase64Key ¶
func GenerateBase64Key(secretLength core.SecretKeyLengthType, secretFormat core.SecretKeyFormatType) (pkStr, pbkStr string, err error)
GenerateBase64Key 生成base64编码的公私钥.
func GenerateECDSAKey ¶
GenerateECDSAKey 生成PEM格式ECDSA公私钥,写入到io.Writer中.
func GenerateECDSAKeyToMemory ¶
func GenerateECDSAKeyToMemory(c elliptic.Curve) (privateBytes []byte, publicBytes []byte, err error)
GenerateECDSAKeyToMemory 生成PEM格式ECDSA公私钥,返回字节格式.
func GenerateRSAKey ¶
GenerateRSAKey 生成PEM格式PKCS1的RSA公私钥,写入到io.Writer中.
func GenerateRSAKeyToMemory ¶
GenerateRSAKeyToMemory 生成PEM格式PKCS1的RSA公私钥,返回字节格式.
func GenerateSSHKey ¶
GenerateSSHKey 生成ssh密钥队.
func HMacMD5 ¶
HMacMD5 md5摘要算法,使用hmac算法生成hash,参数salt是多参数,实现多态的行为. 参考github.com/dxvgef/gommon/encrypt/sha.go中的hash算法.
func ParseRsaPrivateKey ¶
func ParseRsaPrivateKey(derBytes []byte) (privateKey *rsa.PrivateKey, err error)
ParseRsaPrivateKey 解析私钥,derBytes可以使用DecodePemHexBase64函数获取.
func ParseRsaPublicKey ¶
ParseRsaPublicKey 解析公钥,derBytes可以使用DecodePemHexBase64函数获取.
func ParseSM2PublicKey ¶
ParseSM2PublicKey 解析公钥,derBytes可以使用DecodePemHexBase64函数获取.
func RsaPrivateDecrypt ¶
RsaPrivateDecrypt 解析rsa私钥,参数privateKeyStr必须是hex、base64或者是pem编码.
func RsaPublicEncrypt ¶
RsaPublicEncrypt Rsa公钥加密,参数publicKeyStr必须是hex、base64或者是pem编码.
func SM2PublicEncrypt ¶
SM2PublicEncrypt sm2公钥加密,参数publicKeyStr必须是hex、base64或者是pem编码.
func SignByRSA ¶
func SignByRSA(key *rsa.PrivateKey, licenseBytes []byte) (license string, err error)
SignByRSA 使用rsa私钥对象指针签名字符串,返回base64编码的license.
func SignByRSABytes ¶
SignByRSABytes 使用rsa私钥签名字符串,返回base64编码的license.
func SignBySM2 ¶
func SignBySM2(privateKey *sm2.PrivateKey, licenseBytes []byte) (license string, err error)
SignBySM2 使用sm2私钥对象指针签名字符串,返回base64编码的license.
func SignBySM2Bytes ¶
SignBySM2Bytes 使用sm2私钥签名字符串,返回base64编码的license.
func VerifyByRSA ¶
VerifyByRSA 使用rsa公钥验证签名的license.
Types ¶
type BlockStreamMode ¶
type BlockStreamMode string
const ( CTR BlockStreamMode = "CTR" CFB BlockStreamMode = "CFB" OFB BlockStreamMode = "OFB" RC4 BlockStreamMode = "RC4" )