Versions in this module Expand all Collapse all v0 v0.0.1 Jun 21, 2024 Changes in this version + const FILE_BUFFER_SIZE + const MODE_ENCODE_BASE64 + const MODE_ENCODE_HEX_LOWER + const MODE_ENCODE_HEX_UPPER + const MODE_KEY_BASE64 + const MODE_KEY_HEX_LOWER + const MODE_KEY_HEX_UPPER + const MODE_KEY_PEM + const MODE_KEY_STRING + const MODE_PADDING_PKCS5 + const MODE_PADDING_PKCS7 + func DecodingToByte(encodeMode MODE_ENCODE, dataStr string) ([]byte, error) + func EncodingToString(encodeMode MODE_ENCODE, data []byte) (string, error) + func FormatBigInt(bi *big.Int) []byte + func FormatKeyByData(keyData []byte, tag string) (string, error) + func FormatKeyByString(keyStr string, tag string) (string, error) + func GenKeyData(keyLen int) []byte + func GenKeyString(keyMode MODE_KEY, keyLen int, tag string) (string, error) + func KeyIVByteToString(keyMode MODE_KEY, keyData []byte, tag string) (string, error) + func KeyIVStringToByte(keyMode MODE_KEY, keyStr string) ([]byte, error) + func ParseBigInt(iBytes []byte) (*big.Int, error) + func Pkcs5Padding(data []byte, blockSize int) []byte + func Pkcs5UnPadding(decrypted []byte) []byte + func Pkcs7Byte(a int) byte + func Pkcs7Padding(data []byte, blockSize int) []byte + func Pkcs7UnPadding(decrypted []byte) []byte + func ReadFormatKey(str string) ([]byte, error) + func RsaKeyByteToString(keyMode MODE_KEY, keyData []byte, public bool) (string, error) + func RsaKeyStringToByte(keyMode MODE_KEY, keyStr string) ([]byte, error) + func Sm2KeyByteToString(keyMode MODE_KEY, keyData []byte, public bool) (string, error) + func Sm2KeyStringToByte(keyMode MODE_KEY, keyStr string) ([]byte, error) + func Sm3Sum(sha []byte) ([]byte, error) + func Sm3SumByString(encodeMode MODE_ENCODE, str string) (string, error) + func Sm3SumFile(origFile string) ([]byte, error) + func Sm3SumFileByString(encodeMode MODE_ENCODE, origFile string) (string, error) + func Sum(hash crypto.Hash, sha []byte) ([]byte, error) + func SumByString(encodeMode MODE_ENCODE, hash crypto.Hash, str string) (string, error) + func SumFile(hash crypto.Hash, origFile string) ([]byte, error) + func SumFileByString(encodeMode MODE_ENCODE, hash crypto.Hash, origFile string) (string, error) + type EncryptHelper interface + DecDataCBC func(dataEnc []byte) ([]byte, error) + DecDataECB func(dataEnc []byte) ([]byte, error) + DecFileCBC func(fileEnc string, fileDest string) error + DecFileECB func(fileEnc string, fileDest string) error + DecStringCBC func(strEnc string) (string, error) + DecStringECB func(strEnc string) (string, error) + EncDataCBC func(data []byte) ([]byte, error) + EncDataECB func(data []byte) ([]byte, error) + EncFileCBC func(fileSrc string, fileEnc string) error + EncFileECB func(fileSrc string, fileEnc string) error + EncStringCBC func(str string) (string, error) + EncStringECB func(str string) (string, error) + GenIVString func() (string, error) + GenKeyIvData func(len int) ([]byte, error) + GenKeyIvString func(len int) (string, error) + GetBlockSize func() (int, error) + GetIVData func() []byte + GetIVString func() (string, error) + GetKeyData func() []byte + GetKeyString func() (string, error) + ModeOfEncode func() MODE_ENCODE + ModeOfKey func() MODE_KEY + ModeOfPadding func() MODE_PADDING + Padding func(data []byte, blockSize int) []byte + RestoreKeyIV func(keyStr string) ([]byte, error) + SetAutoFillKey func(autoFillKey bool) + SetBlockSize func(blockSize int) + SetIVData func(iv []byte) + SetIVString func(ivStr string) error + SetKeyData func(key []byte) + SetKeyString func(keyStr string) error + UnPadding func(data []byte, blockSize int) []byte + type MODE_ENCODE int + func ParseEncodeMode(encodeMode MODE_ENCODE) MODE_ENCODE + type MODE_KEY int + func ParseKeyMode(keyMode MODE_KEY) MODE_KEY + type MODE_PADDING string + func ParsePaddingMode(paddingMode MODE_PADDING) MODE_PADDING + type RsaHelper interface + DecryptPKCS1v15 func(encMsg []byte) ([]byte, error) + DecryptPKCS1v15Big func(encMsg []byte) ([]byte, error) + DecryptPKCS1v15File func(encFile string, decFile string) error + DecryptPKCS1v15String func(encodeMode MODE_ENCODE, encStr string) (string, error) + DecryptPKCS1v15StringBig func(encodeMode MODE_ENCODE, encStr string) (string, error) + EncryptPKCS1v15 func(origMsg []byte) ([]byte, error) + EncryptPKCS1v15Big func(origMsg []byte) ([]byte, error) + EncryptPKCS1v15File func(origFile string, encFile string, emptyEncrypt bool) error + EncryptPKCS1v15String func(encodeMode MODE_ENCODE, origStr string) (string, error) + EncryptPKCS1v15StringBig func(encodeMode MODE_ENCODE, origStr string) (string, error) + FormatPrivateKey func(modeOfKey MODE_KEY) (string, error) + FormatPublicKey func(modeOfKey MODE_KEY) (string, error) + GenrateKeyPair func(bits int) error + GetSizeOfKey func() int + KeyPair func() (*rsa.PrivateKey, *rsa.PublicKey) + LoadPrivateKey func(modeOfKey MODE_KEY, priKeyStr string) error + LoadPulicKey func(modeOfKey MODE_KEY, pubKeyStr string) error + ModeOfPadding func() MODE_PADDING + SetPrivateKey func(priKey []byte) error + SetPubicKey func(pubKey []byte) error + SetSizeOfKey func(sizeOfKey int) + SignPSS func(hash crypto.Hash, origData []byte, opts *rsa.PSSOptions) ([]byte, error) + SignPSSByString func(encodeMode MODE_ENCODE, hash crypto.Hash, origStr string, opts *rsa.PSSOptions) (string, error) + SignPSSFile func(hash crypto.Hash, origFile string, opts *rsa.PSSOptions) ([]byte, error) + SignPSSFileByString func(encodeMode MODE_ENCODE, hash crypto.Hash, origFile string, ...) (string, error) + SizeOfPrivateKey func() int + SizeOfPublicKey func() int + VerifyPSS func(hash crypto.Hash, origData []byte, sig []byte, opts *rsa.PSSOptions) error + VerifyPSSByString func(encodeMode MODE_ENCODE, hash crypto.Hash, origStr string, sigStr string, ...) error + VerifyPSSFile func(hash crypto.Hash, origFile string, sig []byte, opts *rsa.PSSOptions) error + VerifyPSSFileByString func(encodeMode MODE_ENCODE, hash crypto.Hash, origFile string, sigStr string, ...) error + type SIGN_MARSHAL_MODE int + const SIGN_MARSHAL_ASN1 + const SIGN_MARSHAL_RS + const SIGN_MARSHAL_SR + type SM2_MODE int + type Sm2Helper interface + Decrypt func(encMsg []byte, c1c2c3Mode bool) ([]byte, error) + DecryptAsn1 func(encMsg []byte) ([]byte, error) + DecryptAsn1String func(encodeMode MODE_ENCODE, encStr string) (string, error) + DecryptString func(encodeMode MODE_ENCODE, encStr string, c1c2c3Mode bool) (string, error) + Encrypt func(origMsg []byte, c1c2c3Mode bool) ([]byte, error) + EncryptAsn1 func(origMsg []byte) ([]byte, error) + EncryptAsn1String func(encodeMode MODE_ENCODE, origStr string) (string, error) + EncryptString func(encodeMode MODE_ENCODE, origStr string, c1c2c3Mode bool) (string, error) + FormatPrivateKey func(modeOfKey MODE_KEY, pwd []byte) (string, error) + FormatPublicKey func(modeOfKey MODE_KEY) (string, error) + GenrateKeyPair func() error + GetSizeOfKey func() int + KeyPair func() (*sm2.PrivateKey, *sm2.PublicKey) + LoadPrivateKey func(modeOfKey MODE_KEY, priKeyStr string, pwd []byte) error + LoadPulicKey func(modeOfKey MODE_KEY, pubKeyStr string) error + ModeOfPadding func() MODE_PADDING + SetPrivateKey func(priKey []byte) error + SetPubicKey func(pubKey []byte) error + SetSignMarshalMode func(signMarshalMode SIGN_MARSHAL_MODE) + SetSizeOfKey func(sizeOfKey int) + SizeOfPrivateKey func() int + SizeOfPublicKey func() int + Sm2Sign func(origMsg []byte, uid []byte) ([]byte, error) + Sm2SignString func(encodeMode MODE_ENCODE, origMsg string, uid []byte) (string, error) + Sm2Verify func(origMsg []byte, uid []byte, sign []byte) (bool, error) + Sm2VerifyString func(encodeMode MODE_ENCODE, origMsg string, uid []byte, sigStr string) (bool, error) + type XAes struct + AutoFillKey bool + BlockSize int + Iv []byte + Key []byte + ModeEncode MODE_ENCODE + ModeKey MODE_KEY + ModePadding MODE_PADDING + PaddingHelper func(data []byte, blockSize int) []byte + UnPaddingHelper func(data []byte, blockSize int) []byte + func (x *XAes) DecDataCBC(dataEnc []byte) ([]byte, error) + func (x *XAes) DecDataECB(dataEnc []byte) ([]byte, error) + func (x *XAes) DecFileCBC(pathEnc string, pathDest string) error + func (x *XAes) DecFileECB(pathEnc string, pathDest string) error + func (x *XAes) DecStringCBC(strEnc string) (string, error) + func (x *XAes) DecStringECB(strEnc string) (string, error) + func (x *XAes) EncDataCBC(data []byte) ([]byte, error) + func (x *XAes) EncDataECB(data []byte) ([]byte, error) + func (x *XAes) EncFileCBC(pathSrc string, pathEnc string) error + func (x *XAes) EncFileECB(pathSrc string, pathEnc string) error + func (x *XAes) EncStringCBC(str string) (string, error) + func (x *XAes) EncStringECB(str string) (string, error) + func (x *XAes) GenIVString() (string, error) + func (x *XAes) GenKeyIvData(len int) ([]byte, error) + func (x *XAes) GenKeyIvString(len int) (string, error) + func (x *XAes) GetBlockSize() (int, error) + func (x *XAes) GetIVData() []byte + func (x *XAes) GetIVString() (string, error) + func (x *XAes) GetKeyData() []byte + func (x *XAes) GetKeyString() (string, error) + func (x *XAes) ModeOfEncode() MODE_ENCODE + func (x *XAes) ModeOfKey() MODE_KEY + func (x *XAes) ModeOfPadding() MODE_PADDING + func (x *XAes) Padding(data []byte, blockSize int) []byte + func (x *XAes) RestoreKeyIV(keyStr string) ([]byte, error) + func (x *XAes) SetAutoFillKey(autoFillKey bool) + func (x *XAes) SetBlockSize(blockSize int) + func (x *XAes) SetIVData(iv []byte) + func (x *XAes) SetIVString(ivStr string) error + func (x *XAes) SetKeyData(key []byte) + func (x *XAes) SetKeyString(keyStr string) error + func (x *XAes) UnPadding(data []byte, blockSize int) []byte + type XDes struct + AutoFillKey bool + BlockSize int + Iv []byte + Key []byte + ModeEncode MODE_ENCODE + ModeKey MODE_KEY + ModePadding MODE_PADDING + PaddingHelper func(data []byte, blockSize int) []byte + UnPaddingHelper func(data []byte, blockSize int) []byte + func (x *XDes) DecDataCBC(dataEnc []byte) ([]byte, error) + func (x *XDes) DecDataECB(dataEnc []byte) ([]byte, error) + func (x *XDes) DecFileCBC(pathEnc string, pathDest string) error + func (x *XDes) DecFileECB(pathEnc string, pathDest string) error + func (x *XDes) DecStringCBC(strEnc string) (string, error) + func (x *XDes) DecStringECB(strEnc string) (string, error) + func (x *XDes) EncDataCBC(data []byte) ([]byte, error) + func (x *XDes) EncDataECB(data []byte) ([]byte, error) + func (x *XDes) EncFileCBC(pathSrc string, pathEnc string) error + func (x *XDes) EncFileECB(pathSrc string, pathEnc string) error + func (x *XDes) EncStringCBC(str string) (string, error) + func (x *XDes) EncStringECB(str string) (string, error) + func (x *XDes) GenIVString() (string, error) + func (x *XDes) GenKeyIvData(len int) ([]byte, error) + func (x *XDes) GenKeyIvString(len int) (string, error) + func (x *XDes) GetBlockSize() (int, error) + func (x *XDes) GetIVData() []byte + func (x *XDes) GetIVString() (string, error) + func (x *XDes) GetKeyData() []byte + func (x *XDes) GetKeyString() (string, error) + func (x *XDes) ModeOfEncode() MODE_ENCODE + func (x *XDes) ModeOfKey() MODE_KEY + func (x *XDes) ModeOfPadding() MODE_PADDING + func (x *XDes) Padding(data []byte, blockSize int) []byte + func (x *XDes) RestoreKeyIV(keyStr string) ([]byte, error) + func (x *XDes) SetAutoFillKey(autoFillKey bool) + func (x *XDes) SetBlockSize(blockSize int) + func (x *XDes) SetIVData(iv []byte) + func (x *XDes) SetIVString(ivStr string) error + func (x *XDes) SetKeyData(key []byte) + func (x *XDes) SetKeyString(keyStr string) error + func (x *XDes) UnPadding(data []byte, blockSize int) []byte + type XRsa struct + ModePadding MODE_PADDING + PaddingHelper func(data []byte, blockSize int) []byte + PrivateKey *rsa.PrivateKey + PublicKey *rsa.PublicKey + SizeAuto bool + SizeOfKey int + UnPaddingHelper func(data []byte, blockSize int) []byte + func (x *XRsa) DecryptPKCS1v15(encMsg []byte) ([]byte, error) + func (x *XRsa) DecryptPKCS1v15Big(encMsg []byte) ([]byte, error) + func (x *XRsa) DecryptPKCS1v15File(encFile string, decFile string) error + func (x *XRsa) DecryptPKCS1v15String(encodeMode MODE_ENCODE, encStr string) (string, error) + func (x *XRsa) DecryptPKCS1v15StringBig(encodeMode MODE_ENCODE, encStr string) (string, error) + func (x *XRsa) EncryptPKCS1v15(origMsg []byte) ([]byte, error) + func (x *XRsa) EncryptPKCS1v15Big(origMsg []byte) ([]byte, error) + func (x *XRsa) EncryptPKCS1v15File(origFile string, encFile string, emptyEncrypt bool) error + func (x *XRsa) EncryptPKCS1v15String(encodeMode MODE_ENCODE, origStr string) (string, error) + func (x *XRsa) EncryptPKCS1v15StringBig(encodeMode MODE_ENCODE, origStr string) (string, error) + func (x *XRsa) FormatPrivateKey(modeOfKey MODE_KEY) (string, error) + func (x *XRsa) FormatPublicKey(modeOfKey MODE_KEY) (string, error) + func (x *XRsa) GenrateKeyPair(bits int) error + func (x *XRsa) GetSizeOfKey() int + func (x *XRsa) KeyPair() (*rsa.PrivateKey, *rsa.PublicKey) + func (x *XRsa) LoadPrivateKey(modeOfKey MODE_KEY, priKeyStr string) error + func (x *XRsa) LoadPulicKey(modeOfKey MODE_KEY, pubKeyStr string) error + func (x *XRsa) ModeOfPadding() MODE_PADDING + func (x *XRsa) SetPrivateKey(priKey []byte) error + func (x *XRsa) SetPubicKey(pubKey []byte) error + func (x *XRsa) SetSizeOfKey(sizeOfKey int) + func (x *XRsa) SignPSS(hash crypto.Hash, origData []byte, opts *rsa.PSSOptions) ([]byte, error) + func (x *XRsa) SignPSSByString(encodeMode MODE_ENCODE, hash crypto.Hash, origStr string, opts *rsa.PSSOptions) (string, error) + func (x *XRsa) SignPSSFile(hash crypto.Hash, origFile string, opts *rsa.PSSOptions) ([]byte, error) + func (x *XRsa) SignPSSFileByString(encodeMode MODE_ENCODE, hash crypto.Hash, origFile string, ...) (string, error) + func (x *XRsa) SizeOfPrivateKey() int + func (x *XRsa) SizeOfPublicKey() int + func (x *XRsa) VerifyPSS(hash crypto.Hash, origData []byte, sig []byte, opts *rsa.PSSOptions) error + func (x *XRsa) VerifyPSSByString(encodeMode MODE_ENCODE, hash crypto.Hash, origStr string, sigStr string, ...) error + func (x *XRsa) VerifyPSSFile(hash crypto.Hash, origFile string, sig []byte, opts *rsa.PSSOptions) error + func (x *XRsa) VerifyPSSFileByString(encodeMode MODE_ENCODE, hash crypto.Hash, origFile string, sigStr string, ...) error + type XSm2 struct + ModePadding MODE_PADDING + PaddingHelper func(data []byte, blockSize int) []byte + PrivateKey *sm2.PrivateKey + PublicKey *sm2.PublicKey + SignMarshalMode SIGN_MARSHAL_MODE + SizeAuto bool + SizeOfKey int + UnPaddingHelper func(data []byte, blockSize int) []byte + func (x *XSm2) Decrypt(encMsg []byte, c1c2c3Mode bool) ([]byte, error) + func (x *XSm2) DecryptAsn1(encMsg []byte) ([]byte, error) + func (x *XSm2) DecryptAsn1String(encodeMode MODE_ENCODE, encStr string) (string, error) + func (x *XSm2) DecryptString(encodeMode MODE_ENCODE, encStr string, c1c2c3Mode bool) (string, error) + func (x *XSm2) Encrypt(origMsg []byte, c1c2c3Mode bool) ([]byte, error) + func (x *XSm2) EncryptAsn1(origMsg []byte) ([]byte, error) + func (x *XSm2) EncryptAsn1String(encodeMode MODE_ENCODE, origStr string) (string, error) + func (x *XSm2) EncryptString(encodeMode MODE_ENCODE, origStr string, c1c2c3Mode bool) (string, error) + func (x *XSm2) FormatPrivateKey(modeOfKey MODE_KEY, pwd []byte) (string, error) + func (x *XSm2) FormatPublicKey(modeOfKey MODE_KEY) (string, error) + func (x *XSm2) GenrateKeyPair() error + func (x *XSm2) GetSizeOfKey() int + func (x *XSm2) KeyPair() (*sm2.PrivateKey, *sm2.PublicKey) + func (x *XSm2) LoadPrivateKey(modeOfKey MODE_KEY, priKeyStr string, pwd []byte) error + func (x *XSm2) LoadPulicKey(modeOfKey MODE_KEY, pubKeyStr string) error + func (x *XSm2) ModeOfPadding() MODE_PADDING + func (x *XSm2) SetPrivateKey(priKey []byte) error + func (x *XSm2) SetPubicKey(pubKey []byte) error + func (x *XSm2) SetSignMarshalMode(signMarshalMode SIGN_MARSHAL_MODE) + func (x *XSm2) SetSizeOfKey(sizeOfKey int) + func (x *XSm2) SizeOfPrivateKey() int + func (x *XSm2) SizeOfPublicKey() int + func (x *XSm2) Sm2Sign(origMsg []byte, uid []byte) ([]byte, error) + func (x *XSm2) Sm2SignString(encodeMode MODE_ENCODE, origMsg string, uid []byte) (string, error) + func (x *XSm2) Sm2Verify(origMsg []byte, uid []byte, sign []byte) (bool, error) + func (x *XSm2) Sm2VerifyString(encodeMode MODE_ENCODE, origMsg string, uid []byte, sigStr string) (bool, error) + type XSm4 struct + AutoFillKey bool + BlockSize int + Iv []byte + Key []byte + ModeEncode MODE_ENCODE + ModeKey MODE_KEY + ModePadding MODE_PADDING + PaddingHelper func(data []byte, blockSize int) []byte + UnPaddingHelper func(data []byte, blockSize int) []byte + func (x *XSm4) DecDataCBC(dataEnc []byte) ([]byte, error) + func (x *XSm4) DecDataECB(dataEnc []byte) ([]byte, error) + func (x *XSm4) DecFileCBC(pathEnc string, pathDest string) error + func (x *XSm4) DecFileECB(pathEnc string, pathDest string) error + func (x *XSm4) DecStringCBC(strEnc string) (string, error) + func (x *XSm4) DecStringECB(strEnc string) (string, error) + func (x *XSm4) EncDataCBC(data []byte) ([]byte, error) + func (x *XSm4) EncDataECB(data []byte) ([]byte, error) + func (x *XSm4) EncFileCBC(pathSrc string, pathEnc string) error + func (x *XSm4) EncFileECB(pathSrc string, pathEnc string) error + func (x *XSm4) EncStringCBC(str string) (string, error) + func (x *XSm4) EncStringECB(str string) (string, error) + func (x *XSm4) GenIVString() (string, error) + func (x *XSm4) GenKeyIvData(len int) ([]byte, error) + func (x *XSm4) GenKeyIvString(len int) (string, error) + func (x *XSm4) GetBlockSize() (int, error) + func (x *XSm4) GetIVData() []byte + func (x *XSm4) GetIVString() (string, error) + func (x *XSm4) GetKeyData() []byte + func (x *XSm4) GetKeyString() (string, error) + func (x *XSm4) ModeOfEncode() MODE_ENCODE + func (x *XSm4) ModeOfKey() MODE_KEY + func (x *XSm4) ModeOfPadding() MODE_PADDING + func (x *XSm4) Padding(data []byte, blockSize int) []byte + func (x *XSm4) RestoreKeyIV(keyStr string) ([]byte, error) + func (x *XSm4) SetAutoFillKey(autoFillKey bool) + func (x *XSm4) SetBlockSize(blockSize int) + func (x *XSm4) SetIVData(iv []byte) + func (x *XSm4) SetIVString(ivStr string) error + func (x *XSm4) SetKeyData(key []byte) + func (x *XSm4) SetKeyString(keyStr string) error + func (x *XSm4) UnPadding(data []byte, blockSize int) []byte