Documentation
¶
Index ¶
- Constants
- Variables
- func AESDecryptByCBC(cipherTextBase64 string, keyBase, ivBase string) ([]byte, error)
- func AESDecryptByCCM(cipherTextBase64 string, keyBase, ivBase string) ([]byte, error)
- func AESDecryptByCTR(cipherTextBase64 string, keyBase, ivBase string) ([]byte, error)
- func AESDecryptByGCM(cipherTextBase64 string, keyBase, ivBase string) ([]byte, error)
- func AESDecryptByGCMBt(cipherTextBt, key, iv []byte) ([]byte, error)
- func AESEncryptByCBC(plainText []byte, keyBase, ivBase string) (string, error)
- func AESEncryptByCCM(plainText []byte, keyBase, ivBase string) (string, error)
- func AESEncryptByCTR(plainText []byte, keyBase, ivBase string) (string, error)
- func AESEncryptByGCM(plainText []byte, keyBase, ivBase string) (string, error)
- func AESEncryptByGCMBt(plainText, key, iv []byte) ([]byte, error)
- func CBCPkcs7Pad(data []byte, blockSize int) []byte
- func CBCPkcs7Unpad(data []byte) []byte
- func ECDSAGenerateECCCertificate(curve elliptic.Curve, subject pkix.Name) (keyPem, certPem []byte, err error)
- func ECDSAGenerateKeys(curve elliptic.Curve) (privateKey *ecdsa.PrivateKey, publicKey *ecdsa.PublicKey, err error)
- func GenAESKeyAndIv(KeyLen int, IvLen int) (keyBase, ivBase string, err error)
- func GenRsaKey2Bt(btLen int) (privateKeyBt, publicKeyBt []byte, err error)
- func GenRsaKey2Str(btLen int) (privateKeyStr, publicKeyStr *string, err error)
- func HMACSha256(data string, key string) (hexStr string, baseStr string)
- func HMACSha512(data string, key string) (hexStr string, baseStr string)
- func ParseECDSAPrivateKeyFromPEM(privateKeyPEM string) (*ecdsa.PrivateKey, error)
- func ParseECDSAPublicKeyFromCert(certPEM string) (*ecdsa.PublicKey, error)
- func ParseRSAPrivateKey(pemData string) (*rsa.PrivateKey, error)
- func ParseRSAPublicKey(pemData string) (*rsa.PublicKey, error)
- func RSADecrypt(method hash.Hash, encryptedBase64 string, privateKey *rsa.PrivateKey) ([]byte, error)
- func RSADecryptBySha256(encryptedBase64 string, privateKey *rsa.PrivateKey) ([]byte, error)
- func RSADecryptBySha512(encryptedBase64 string, privateKey *rsa.PrivateKey) ([]byte, error)
- func RSAEncrypt(method hash.Hash, plainText []byte, publicKey *rsa.PublicKey) (string, error)
- func RSAEncryptBySha256(plainText []byte, publicKey *rsa.PublicKey) (string, error)
- func RSAEncryptBySha512(plainText []byte, publicKey *rsa.PublicKey) (string, error)
- func RSAGenerateKeys(bits int) (privateKey *rsa.PrivateKey, publicKey *rsa.PublicKey, err error)
- func RSAParsePrivateKey2Bt(privateKey *rsa.PrivateKey) (prvKeyBt []byte, err error)
- func RSAParsePublicKey2Bt(publicKey *rsa.PublicKey) (pubKeyBt []byte, err error)
- func Sha256(data string) (hexStr string, baseStr string)
- func Sha512(data string) (hexStr string, baseStr string)
- type Argon2Config
- type Argon2Tool
- type BitLen
- type HashTool
- type RandTool
Constants ¶
View Source
const ( AES128KeyLen = 16 AES192KeyLen = 24 AES256KeyLen = 32 AESGCMIvLen = 12 AESCCMIvLen = 24 AEsCBCIvLen = 16 AESCTRIvLen = 16 )
View Source
const ( DefaultArgon2Time uint32 = 3 DefaultArgon2MemoryKiB uint32 = 65536 // 64 MiB DefaultArgon2Threads uint8 = 2 DefaultArgon2KeyLen uint32 = 32 DefaultArgon2SaltLen = Bits256Len // 128 bits )
Variables ¶
View Source
var ( Argon2ErrEmptySecret = errors.New("empty secret") Argon2ErrPhcFormatBad = errors.New("bad phc format") Argon2ErrPhcParamsBad = errors.New("bad phc params") Argon2ErrPhcVersionBad = errors.New("bad alg version") )
Functions ¶
func AESDecryptByCBC ¶
**AES-CBC 解密**
func AESDecryptByCCM ¶
**AES-CCM 解密**
func AESDecryptByCTR ¶
**AES-CTR 解密**
func AESDecryptByGCM ¶
**AES-GCM 解密**
func AESDecryptByGCMBt ¶ added in v1.0.58
**AES-GCM 解密**
func AESEncryptByCBC ¶
**AES-CBC 加密**
func AESEncryptByCCM ¶
**AES-CCM 加密**
func AESEncryptByCTR ¶
**AES-CTR 加密**
func AESEncryptByGCM ¶
**AES-GCM 加密**
func AESEncryptByGCMBt ¶ added in v1.0.57
func ECDSAGenerateECCCertificate ¶
func ECDSAGenerateECCCertificate(curve elliptic.Curve, subject pkix.Name) (keyPem, certPem []byte, err error)
note: 生成 ECC 证书
func ECDSAGenerateKeys ¶
func ECDSAGenerateKeys(curve elliptic.Curve) (privateKey *ecdsa.PrivateKey, publicKey *ecdsa.PublicKey, err error)
note: 生成 ECDSA 公私钥
func GenAESKeyAndIv ¶
func GenRsaKey2Bt ¶
note: 生成 RSA 公私钥并解析到bt
func GenRsaKey2Str ¶
note: 生成 RSA 公私钥并解析到字符串
func ParseECDSAPrivateKeyFromPEM ¶
func ParseECDSAPrivateKeyFromPEM(privateKeyPEM string) (*ecdsa.PrivateKey, error)
**解析 ECDSA 公钥 **
func ParseRSAPrivateKey ¶
func ParseRSAPrivateKey(pemData string) (*rsa.PrivateKey, error)
解析 PEM 格式的私钥
func ParseRSAPublicKey ¶
解析 PEM 格式的公钥
func RSADecrypt ¶
func RSADecrypt(method hash.Hash, encryptedBase64 string, privateKey *rsa.PrivateKey) ([]byte, error)
RSA + SHA-512 进行解密
func RSADecryptBySha256 ¶
func RSADecryptBySha256(encryptedBase64 string, privateKey *rsa.PrivateKey) ([]byte, error)
RSA + SHA-256 进行解密
func RSADecryptBySha512 ¶
func RSADecryptBySha512(encryptedBase64 string, privateKey *rsa.PrivateKey) ([]byte, error)
RSA + SHA-512 进行解密
func RSAEncrypt ¶
RSA + SHA-512 进行加密
func RSAEncryptBySha256 ¶
RSA + SHA-256 进行加密
func RSAEncryptBySha512 ¶
RSA + SHA-512 进行加密
func RSAGenerateKeys ¶
note: 生成 RSA 公私钥
func RSAParsePrivateKey2Bt ¶
func RSAParsePrivateKey2Bt(privateKey *rsa.PrivateKey) (prvKeyBt []byte, err error)
note: 解析私钥到字节
func RSAParsePublicKey2Bt ¶
note: 解析公钥到字节
Types ¶
type Argon2Config ¶ added in v1.0.54
type Argon2Config struct {
Time uint32 // Time cose
MemoryKiB uint32 // Memory cost
Threads uint8 // Parallelism degree
KeyLen uint32 // KeyLen
SaltLen BitLen // Salt
}
func DefaultArgon2Config ¶ added in v1.0.54
func DefaultArgon2Config() *Argon2Config
type Argon2Tool ¶ added in v1.0.56
type Argon2Tool interface {
GetConfig() *Argon2Config
HashToPHC(secret, pepper []byte) (SelfContained string, err error)
VerifyPhc(phc string, secret, pepper []byte) (result bool, err error)
VerifyWithPepperSet(phc string, secret []byte, pepperCurrent, pepperOld []byte) (ok bool, rehashWith []byte, err error)
NeedsRehash(phc string) (bool, error)
ParsePHC(phc string) (algo, ver string, m uint32, t uint32, p uint8, salt, hash []byte, err error)
}
func NewArgon2Tool ¶ added in v1.0.54
func NewArgon2Tool(conf *Argon2Config) Argon2Tool
type HashTool ¶ added in v1.0.62
type RandTool ¶ added in v1.0.66
type RandTool interface {
GetAnyBtLen(num int) BitLen
RandInt(min, max int) int
RandInt64(min, max int64) int64
RandLowerString(stringLen int) string
RandStringRunes(n int) string
GenValidateCode(width int) string
RandBytesHexNoErr(btLen BitLen) string
RandBytesHex(btLen BitLen) (string, error)
RandBytesBase(btLen BitLen) (string, error)
RandBytesBaseNoErr(btLen BitLen) string
RandBytesUrlBase(btLen BitLen) (string, error)
RandBytesUrlBaseNoErr(btLen BitLen) string
RandBytes(btLen BitLen) ([]byte, error)
RandBytesNoErr(btLen BitLen) []byte
}
Click to show internal directories.
Click to hide internal directories.