Documentation ¶
Index ¶
- Constants
- Variables
- func PKCS7Padding(ciphertext []byte, blockSize int) []byte
- func PKCS7UnPadding(origData []byte) []byte
- type AesEncrypt
- type AesKeyType
- type AesModeType
- type DesEncrypt
- type RsaBitsType
- type RsaEncrypt
- func (r *RsaEncrypt) DecryptByte(src string) []byte
- func (r *RsaEncrypt) EncryptString(retByte []byte) string
- func (r *RsaEncrypt) RsaDecrypt(srcByte []byte, filePath string) (string, error)
- func (r *RsaEncrypt) RsaEncrypt(src, filePath string) ([]byte, error)
- func (r *RsaEncrypt) SaveRsaKey() error
- type TripleDesEncrypt
Constants ¶
View Source
const ( // 密钥长度 AesKeyLength128 = 16 AesKeyLength192 = 24 AesKeyLength256 = 32 // IVLength 初始向量 16 字节 IVLength = 16 )
View Source
const ( RsaDefaultPublishKeyName = "publishKey" RsaDefaultPrivateKeyName = "privateKey" PublishKey = "PUBLIC KEY" PrivateKey = "RSA PRIVATE KEY" )
View Source
const DesKeyLength = 8
View Source
const TripleDesKeyBlock = 8
View Source
const TripleDesKeyLength = 24
Variables ¶
View Source
var BaseSpecialSign = "!@a%$bc.de,l%$fgqweruriskn&#@xl784zm321apgiw"
View Source
var BaseSpecialSignLength = len(BaseSpecialSign)
View Source
var RsaBitsMap = map[RsaBitsType]int{ RsaBits512: 512, RsaBits1024: 1024, RsaBits2048: 2048, RsaBits4096: 4096, }
Functions ¶
func PKCS7Padding ¶ added in v1.0.4
func PKCS7UnPadding ¶ added in v1.0.4
Types ¶
type AesEncrypt ¶
type AesEncrypt struct { SpecialSign string // 加解密都会基于这一串字符,如果没有会基于 AesBaseSpecialSign. Key string // 密钥,建议是 5-8位的密钥 IV string // 初始向量 16 字节 AesModeType AesModeType // 加密类型 AesKeyType AesKeyType // 加密类型 AesKey []byte // AES 密钥 AesKeyLength int // 加密长度 PlainTextLength int // 加密的长度 }
func NewAesEncrypt ¶
func NewAesEncrypt(specialSign, key, iv string, aesKeyType AesKeyType, aesModeType AesModeType) (*AesEncrypt, error)
func (*AesEncrypt) SecretDecrypt ¶
func (a *AesEncrypt) SecretDecrypt(secret interface{}) string
SecretDecrypt 解密
func (*AesEncrypt) SecretEncrypt ¶
func (a *AesEncrypt) SecretEncrypt(secret interface{}) string
SecretEncrypt 加密
type AesKeyType ¶ added in v1.0.3
type AesKeyType uint64 // 密钥类型
const ( AesEncrypt128 AesKeyType = 128 AesEncrypt192 AesKeyType = 192 AesEncrypt256 AesKeyType = 256 )
AES 密钥类型
type AesModeType ¶ added in v1.0.3
type AesModeType string // 加密模式类型
const ( AesModeTypeCBC AesModeType = "CBC" // Cipher Block Chaining AesModeTypeCFB AesModeType = "CFB" // Cipher FeedBack AesModeTypeCTR AesModeType = "CTR" // Counter AesModeTypeOFB AesModeType = "OFB" // Output FeedBack AesModeTypeECB AesModeType = "ECB" // Electronic Codebook )
AES 加密模式
type DesEncrypt ¶
type DesEncrypt struct { SpecialSign string // 加解密都会基于这一串字符,如果没有会基于 DesBaseSpecialSign. Key string // 密钥,建议是 5-8位的密钥 }
func NewDesEncrypt ¶
func NewDesEncrypt(specialSign, key string) (*DesEncrypt, error)
func (*DesEncrypt) SecretDecrypt ¶
func (d *DesEncrypt) SecretDecrypt(secret interface{}, fields ...interface{}) (string, error)
SecretDecrypt 解密
func (*DesEncrypt) SecretEncrypt ¶
func (d *DesEncrypt) SecretEncrypt(secret interface{}, fields ...interface{}) (string, error)
SecretEncrypt 加密
type RsaBitsType ¶
type RsaBitsType int
const ( RsaBits512 RsaBitsType = 512 RsaBits1024 RsaBitsType = 1024 RsaBits2048 RsaBitsType = 2048 RsaBits4096 RsaBitsType = 4096 RsaDefaultBits = RsaBits1024 )
type RsaEncrypt ¶
type RsaEncrypt struct { Bits RsaBitsType // 定位大小的 RSA 密钥对 PublishKeyName string // 公钥名字 PrivateKeyName string // 私钥名字 PublishKeyPath string // 公钥的输出路径 PrivateKeyPath string // 私钥的输出路径 }
func NewDefaultRsaEncrypt ¶
func NewDefaultRsaEncrypt() *RsaEncrypt
func NewRsaEncrypt ¶
func NewRsaEncrypt(bits RsaBitsType, publishKeyName, publishKeyPath, privateKeyName, privateKeyPath string) *RsaEncrypt
func (*RsaEncrypt) DecryptByte ¶ added in v1.0.3
func (r *RsaEncrypt) DecryptByte(src string) []byte
func (*RsaEncrypt) EncryptString ¶ added in v1.0.2
func (r *RsaEncrypt) EncryptString(retByte []byte) string
EncryptString String输出加密后的东西
func (*RsaEncrypt) RsaDecrypt ¶ added in v1.0.1
func (r *RsaEncrypt) RsaDecrypt(srcByte []byte, filePath string) (string, error)
RsaDecrypt 解密
func (*RsaEncrypt) RsaEncrypt ¶ added in v1.0.1
func (r *RsaEncrypt) RsaEncrypt(src, filePath string) ([]byte, error)
RsaEncrypt 加密
type TripleDesEncrypt ¶
type TripleDesEncrypt struct { SpecialSign string // 加解密都会基于这一串字符,如果没有会基于 TripleDesBaseSpecialSign. Key string // 密钥,建议是 5-8位的密钥 }
func NewTripleDesEncrypt ¶
func NewTripleDesEncrypt(specialSign, key string) (*TripleDesEncrypt, error)
func (*TripleDesEncrypt) SecretDecrypt ¶
func (t *TripleDesEncrypt) SecretDecrypt(secret interface{}, fields ...interface{}) (string, error)
SecretDecrypt 解密
func (*TripleDesEncrypt) SecretEncrypt ¶
func (t *TripleDesEncrypt) SecretEncrypt(secret interface{}, fields ...interface{}) (string, error)
SecretEncrypt 加密
Click to show internal directories.
Click to hide internal directories.