Documentation ¶
Index ¶
- Constants
- Variables
- func AddOidAsn1(name string, identifier asn1.ObjectIdentifier)
- func AddOidHash(name string, value func() hash.Hash)
- func AddRfc1423Algo(value rfc1423Algo)
- func DecryptPEMBlock(block *pem.Block, password []byte) ([]byte, error)
- func DecryptPKCS8PrivateKey(data, password []byte) ([]byte, error)
- func EncryptPKCS8PrivateKey(rand io.Reader, blockType string, data []byte, password []byte, ...) (*pem.Block, error)
- type CryptoHashMap
- type Cryptobin
- func (this Cryptobin) Aes() Cryptobin
- func (this Cryptobin) AesCFBDecrypt() Cryptobin
- func (this Cryptobin) AesCFBEncrypt() Cryptobin
- func (this Cryptobin) AesECBDecrypt() Cryptobin
- func (this Cryptobin) AesECBEncrypt() Cryptobin
- func (this Cryptobin) AesECBGenerateKey(key []byte) (genKey []byte)
- func (this Cryptobin) Blowfish(salt ...string) Cryptobin
- func (this Cryptobin) CBC() Cryptobin
- func (this Cryptobin) CFB() Cryptobin
- func (this Cryptobin) CTR() Cryptobin
- func (this Cryptobin) Cast5() Cryptobin
- func (this Cryptobin) Chacha20(nonce string, counter ...uint32) Cryptobin
- func (this Cryptobin) Chacha20poly1305(nonce string, additional string) Cryptobin
- func (this Cryptobin) CipherBlock(key []byte) (cipher.Block, error)
- func (this Cryptobin) CipherDecrypt() Cryptobin
- func (this Cryptobin) CipherEncrypt() Cryptobin
- func (this Cryptobin) Decrypt() Cryptobin
- func (this Cryptobin) Des() Cryptobin
- func (this Cryptobin) ECB() Cryptobin
- func (this Cryptobin) Encrypt() Cryptobin
- func (this Cryptobin) FromBase64String(data string) Cryptobin
- func (this Cryptobin) FromBytes(data []byte) Cryptobin
- func (this Cryptobin) FromHexString(data string) Cryptobin
- func (this Cryptobin) FromString(data string) Cryptobin
- func (this Cryptobin) FuncDecrypt(f func(Cryptobin) Cryptobin) Cryptobin
- func (this Cryptobin) FuncEncrypt(f func(Cryptobin) Cryptobin) Cryptobin
- func (this Cryptobin) GCM(nonce string, additional string) Cryptobin
- func (this Cryptobin) GetConfig() map[string]any
- func (this Cryptobin) GetData() []byte
- func (this Cryptobin) GetError() error
- func (this Cryptobin) GetIv() []byte
- func (this Cryptobin) GetKey() []byte
- func (this Cryptobin) GetMode() string
- func (this Cryptobin) GetMultiple() string
- func (this Cryptobin) GetOneConfig(key string) any
- func (this Cryptobin) GetPadding() string
- func (this Cryptobin) GetParsedData() []byte
- func (this Cryptobin) GuessDecrypt() Cryptobin
- func (this Cryptobin) GuessEncrypt() Cryptobin
- func (this Cryptobin) ISO10126Padding() Cryptobin
- func (this Cryptobin) ISO7816_4Padding() Cryptobin
- func (this Cryptobin) NoPadding() Cryptobin
- func (this Cryptobin) NoParse() Cryptobin
- func (this Cryptobin) OFB() Cryptobin
- func (this Cryptobin) PKCS1Padding(bt ...string) Cryptobin
- func (this Cryptobin) PKCS5Padding() Cryptobin
- func (this Cryptobin) PKCS7Padding() Cryptobin
- func (this Cryptobin) Padding(plainText []byte, blockSize int) []byte
- func (this Cryptobin) RC4() Cryptobin
- func (this Cryptobin) RsaDecrypt(password ...string) Cryptobin
- func (this Cryptobin) RsaEncrypt() Cryptobin
- func (this Cryptobin) RsaOAEPDecrypt(typ string, password ...string) Cryptobin
- func (this Cryptobin) RsaOAEPEncrypt(typ string) Cryptobin
- func (this Cryptobin) RsaPrikeyEncrypt(password ...string) Cryptobin
- func (this Cryptobin) RsaPubkeyDecrypt() Cryptobin
- func (this Cryptobin) SM2Decrypt(password ...string) Cryptobin
- func (this Cryptobin) SM2Encrypt() Cryptobin
- func (this Cryptobin) SM4() Cryptobin
- func (this Cryptobin) SetIv(data string) Cryptobin
- func (this Cryptobin) SetKey(data string) Cryptobin
- func (this Cryptobin) String() string
- func (this Cryptobin) TBCPadding() Cryptobin
- func (this Cryptobin) Tea(rounds ...int) Cryptobin
- func (this Cryptobin) ToBase64String() string
- func (this Cryptobin) ToBytes() []byte
- func (this Cryptobin) ToHexString() string
- func (this Cryptobin) ToString() string
- func (this Cryptobin) TriDes() Cryptobin
- func (this Cryptobin) Twofish() Cryptobin
- func (this Cryptobin) UnPadding(cipherText []byte) []byte
- func (this Cryptobin) WithConfig(config map[string]any) Cryptobin
- func (this Cryptobin) WithData(data []byte) Cryptobin
- func (this Cryptobin) WithError(err error) Cryptobin
- func (this Cryptobin) WithIv(iv []byte) Cryptobin
- func (this Cryptobin) WithKey(key []byte) Cryptobin
- func (this Cryptobin) WithMode(mode string) Cryptobin
- func (this Cryptobin) WithMultiple(multiple string) Cryptobin
- func (this Cryptobin) WithOneConfig(key string, value any) Cryptobin
- func (this Cryptobin) WithPadding(padding string) Cryptobin
- func (this Cryptobin) X923Padding() Cryptobin
- func (this Cryptobin) Xtea() Cryptobin
- func (this Cryptobin) ZeroPadding() Cryptobin
- type Ecdsa
- func EcdsaFromBase64String(data string) Ecdsa
- func EcdsaFromBytes(data []byte) Ecdsa
- func EcdsaFromHexString(data string) Ecdsa
- func EcdsaFromPrivateKey(key []byte) Ecdsa
- func EcdsaFromPublicKey(key []byte) Ecdsa
- func EcdsaFromString(data string) Ecdsa
- func EcdsaGenerateKey(hash string) Ecdsa
- func NewEcdsa() Ecdsa
- func (this Ecdsa) CreatePrivateKey() Ecdsa
- func (this Ecdsa) CreatePublicKey() Ecdsa
- func (this Ecdsa) DataHash(signHash string, data []byte) []byte
- func (this Ecdsa) FromBase64String(data string) Ecdsa
- func (this Ecdsa) FromBytes(data []byte) Ecdsa
- func (this Ecdsa) FromHexString(data string) Ecdsa
- func (this Ecdsa) FromPrivateKey(key []byte) Ecdsa
- func (this Ecdsa) FromPrivateKeyBytes(priByte []byte) Ecdsa
- func (this Ecdsa) FromPrivateKeyDBytes(DBytes []byte) Ecdsa
- func (this Ecdsa) FromPrivateKeyString(keyString string) Ecdsa
- func (this Ecdsa) FromPublicKey(key []byte) Ecdsa
- func (this Ecdsa) FromPublicKeyString(keyString string) Ecdsa
- func (this Ecdsa) FromPublicKeyXYBytes(XBytes, YBytes []byte) Ecdsa
- func (this Ecdsa) FromString(data string) Ecdsa
- func (this Ecdsa) GenerateKey() Ecdsa
- func (this Ecdsa) GetData() []byte
- func (this Ecdsa) GetError() error
- func (this Ecdsa) GetKeyData() []byte
- func (this Ecdsa) GetParedData() []byte
- func (this Ecdsa) GetPrivateKey() *ecdsa.PrivateKey
- func (this Ecdsa) GetPrivateKeyCurve() elliptic.Curve
- func (this Ecdsa) GetPrivateKeyD() *big.Int
- func (this Ecdsa) GetPrivateKeyX() *big.Int
- func (this Ecdsa) GetPrivateKeyY() *big.Int
- func (this Ecdsa) GetPublicKey() *ecdsa.PublicKey
- func (this Ecdsa) GetPublicKeyCurve() elliptic.Curve
- func (this Ecdsa) GetPublicKeyX() *big.Int
- func (this Ecdsa) GetPublicKeyY() *big.Int
- func (this Ecdsa) GetSignHash() string
- func (this Ecdsa) GetVeryed() bool
- func (this Ecdsa) ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error)
- func (this Ecdsa) ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error)
- func (this Ecdsa) Sign(separator ...string) Ecdsa
- func (this Ecdsa) SignAsn1() Ecdsa
- func (this Ecdsa) SignHex() Ecdsa
- func (this Ecdsa) ToBase64String() string
- func (this Ecdsa) ToBytes() []byte
- func (this Ecdsa) ToHexString() string
- func (this Ecdsa) ToKeyBytes() []byte
- func (this Ecdsa) ToKeyString() string
- func (this Ecdsa) ToString() string
- func (this Ecdsa) ToVeryed() bool
- func (this Ecdsa) VerifyAsn1(data []byte) Ecdsa
- func (this Ecdsa) VerifyHex(data []byte) Ecdsa
- func (this Ecdsa) Very(data []byte, separator ...string) Ecdsa
- func (this Ecdsa) WithCurve(curve string) Ecdsa
- func (this Ecdsa) WithData(data []byte) Ecdsa
- func (this Ecdsa) WithError(err error) Ecdsa
- func (this Ecdsa) WithParedData(data []byte) Ecdsa
- func (this Ecdsa) WithPrivateKey(data *ecdsa.PrivateKey) Ecdsa
- func (this Ecdsa) WithPublicKey(data *ecdsa.PublicKey) Ecdsa
- func (this Ecdsa) WithSignHash(hash string) Ecdsa
- type EdDSA
- func EdDSAFromBase64String(data string) EdDSA
- func EdDSAFromBytes(data []byte) EdDSA
- func EdDSAFromHexString(data string) EdDSA
- func EdDSAFromPrivateKey(key []byte) EdDSA
- func EdDSAFromPublicKey(key []byte) EdDSA
- func EdDSAFromString(data string) EdDSA
- func EdDSAGenerateKey() EdDSA
- func NewEdDSA() EdDSA
- func (this EdDSA) CreatePrivateKey() EdDSA
- func (this EdDSA) CreatePublicKey() EdDSA
- func (this EdDSA) FromBase64String(data string) EdDSA
- func (this EdDSA) FromBytes(data []byte) EdDSA
- func (this EdDSA) FromHexString(data string) EdDSA
- func (this EdDSA) FromPrivateKey(key []byte) EdDSA
- func (this EdDSA) FromPublicKey(key []byte) EdDSA
- func (this EdDSA) FromString(data string) EdDSA
- func (this EdDSA) GenerateKey() EdDSA
- func (this EdDSA) GetData() []byte
- func (this EdDSA) GetError() error
- func (this EdDSA) GetKeyData() []byte
- func (this EdDSA) GetParedData() []byte
- func (this EdDSA) GetPrivateKey() ed25519.PrivateKey
- func (this EdDSA) GetPublicKey() ed25519.PublicKey
- func (this EdDSA) GetVeryed() bool
- func (this EdDSA) ParseEdPrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error)
- func (this EdDSA) ParseEdPublicKeyFromPEM(key []byte) (crypto.PublicKey, error)
- func (this EdDSA) Sign() EdDSA
- func (this EdDSA) ToBase64String() string
- func (this EdDSA) ToBytes() []byte
- func (this EdDSA) ToHexString() string
- func (this EdDSA) ToKeyBytes() []byte
- func (this EdDSA) ToKeyString() string
- func (this EdDSA) ToString() string
- func (this EdDSA) ToVeryed() bool
- func (this EdDSA) Very(data []byte) EdDSA
- func (this EdDSA) WithData(data []byte) EdDSA
- func (this EdDSA) WithError(err error) EdDSA
- func (this EdDSA) WithParedData(data []byte) EdDSA
- func (this EdDSA) WithPrivateKey(data ed25519.PrivateKey) EdDSA
- func (this EdDSA) WithPublicKey(data ed25519.PublicKey) EdDSA
- type Encoding
- type Hash
- func (this Hash) AddCryptoHash(name string, sha crypto.Hash) Hash
- func (this Hash) AddHash(name string, sha hashFunc) Hash
- func (this Hash) DataCryptoHash(typ string, slices ...[]byte) []byte
- func (this Hash) DataHash(typ string, slices ...[]byte) []byte
- func (this Hash) GetCryptoHash(typ string) crypto.Hash
- func (this Hash) GetHash(typ string) hashFunc
- func (this Hash) WithCryptoHashs(hashes CryptoHashMap) Hash
- func (this Hash) WithHashs(hashes HashMap) Hash
- type HashMap
- type Opts
- type Padding
- func (this Padding) ISO10126Padding(text []byte, blockSize int) []byte
- func (this Padding) ISO10126UnPadding(src []byte) []byte
- func (this Padding) ISO7816_4Padding(text []byte, blockSize int) []byte
- func (this Padding) ISO7816_4UnPadding(src []byte) []byte
- func (this Padding) PKCS1Padding(text []byte, blockSize int, bt string) []byte
- func (this Padding) PKCS1UnPadding(src []byte) []byte
- func (this Padding) PKCS5Padding(text []byte) []byte
- func (this Padding) PKCS5UnPadding(src []byte) []byte
- func (this Padding) PKCS7Padding(text []byte, blockSize int) []byte
- func (this Padding) PKCS7UnPadding(src []byte) []byte
- func (this Padding) RandomBytes(length uint) []byte
- func (this Padding) TBCPadding(text []byte, blockSize int) []byte
- func (this Padding) TBCUnPadding(src []byte) []byte
- func (this Padding) X923Padding(text []byte, blockSize int) []byte
- func (this Padding) X923UnPadding(src []byte) []byte
- func (this Padding) ZeroPadding(text []byte, blockSize int) []byte
- func (this Padding) ZeroUnPadding(src []byte) []byte
- type Rsa
- func NewRsa() Rsa
- func RsaFromBase64String(data string) Rsa
- func RsaFromBytes(data []byte) Rsa
- func RsaFromHexString(data string) Rsa
- func RsaFromPKCS1(key []byte) Rsa
- func RsaFromPKCS1WithPassword(key []byte, password string) Rsa
- func RsaFromPKCS8(key []byte) Rsa
- func RsaFromPKCS8WithPassword(key []byte, password string) Rsa
- func RsaFromPrivateKey(key []byte) Rsa
- func RsaFromPrivateKeyWithPassword(key []byte, password string) Rsa
- func RsaFromPublicKey(key []byte) Rsa
- func RsaFromString(data string) Rsa
- func RsaFromYoumarkPKCS8WithPassword(key []byte, password string) Rsa
- func RsaGenerateKey(bits int) Rsa
- func (this Rsa) CreatePKCS1() Rsa
- func (this Rsa) CreatePKCS1WithPassword(password string, opts ...string) Rsa
- func (this Rsa) CreatePKCS8() Rsa
- func (this Rsa) CreatePKCS8WithPassword(password string, opts ...string) Rsa
- func (this Rsa) CreatePublicKey() Rsa
- func (this Rsa) CreateYoumarkPKCS8WithPassword(password string, opt ...youmarkPkcs8.Opts) Rsa
- func (this Rsa) Decrypt() Rsa
- func (this Rsa) DecryptOAEP(typ ...string) Rsa
- func (this Rsa) Encrypt() Rsa
- func (this Rsa) EncryptOAEP(typ ...string) Rsa
- func (this Rsa) FromBase64String(data string) Rsa
- func (this Rsa) FromBytes(data []byte) Rsa
- func (this Rsa) FromHexString(data string) Rsa
- func (this Rsa) FromPKCS1(key []byte) Rsa
- func (this Rsa) FromPKCS1WithPassword(key []byte, password string) Rsa
- func (this Rsa) FromPKCS8(key []byte) Rsa
- func (this Rsa) FromPKCS8WithPassword(key []byte, password string) Rsa
- func (this Rsa) FromPrivateKey(key []byte) Rsa
- func (this Rsa) FromPrivateKeyWithPassword(key []byte, password string) Rsa
- func (this Rsa) FromPublicKey(key []byte) Rsa
- func (this Rsa) FromString(data string) Rsa
- func (this Rsa) FromYoumarkPKCS8WithPassword(key []byte, password string) Rsa
- func (this Rsa) GenerateKey(bits int) Rsa
- func (this Rsa) GetData() []byte
- func (this Rsa) GetError() error
- func (this Rsa) GetKeyData() []byte
- func (this Rsa) GetParedData() []byte
- func (this Rsa) GetPrivateKey() *rsa.PrivateKey
- func (this Rsa) GetPublicKey() *rsa.PublicKey
- func (this Rsa) GetSignHash() string
- func (this Rsa) GetVeryed() bool
- func (this Rsa) PSSSign(opts ...rsa.PSSOptions) Rsa
- func (this Rsa) PSSVery(data []byte, opts ...rsa.PSSOptions) Rsa
- func (this Rsa) ParseRSAPKCS8PrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error)
- func (this Rsa) ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)
- func (this Rsa) ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error)
- func (this Rsa) ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)
- func (this Rsa) PriKeyEncrypt() Rsa
- func (this Rsa) PubKeyDecrypt() Rsa
- func (this Rsa) Sign() Rsa
- func (this Rsa) ToBase64String() string
- func (this Rsa) ToBytes() []byte
- func (this Rsa) ToHexString() string
- func (this Rsa) ToKeyBytes() []byte
- func (this Rsa) ToKeyString() string
- func (this Rsa) ToString() string
- func (this Rsa) ToVeryed() bool
- func (this Rsa) Very(data []byte) Rsa
- func (this Rsa) WithData(data []byte) Rsa
- func (this Rsa) WithError(err error) Rsa
- func (this Rsa) WithParedData(data []byte) Rsa
- func (this Rsa) WithPrivateKey(data *rsa.PrivateKey) Rsa
- func (this Rsa) WithPublicKey(data *rsa.PublicKey) Rsa
- func (this Rsa) WithSignHash(data string) Rsa
- type SM2
- func NewSM2() SM2
- func SM2FromBase64String(data string) SM2
- func SM2FromBytes(data []byte) SM2
- func SM2FromHexString(data string) SM2
- func SM2FromPrivateKey(key []byte) SM2
- func SM2FromPrivateKeyWithPassword(key []byte, password string) SM2
- func SM2FromPublicKey(key []byte) SM2
- func SM2FromString(data string) SM2
- func SM2GenerateKey() SM2
- func (this SM2) CreatePrivateKey() SM2
- func (this SM2) CreatePrivateKeyWithPassword(password string) SM2
- func (this SM2) CreatePublicKey() SM2
- func (this SM2) Decrypt() SM2
- func (this SM2) Encrypt() SM2
- func (this SM2) FromBase64String(data string) SM2
- func (this SM2) FromBytes(data []byte) SM2
- func (this SM2) FromHexString(data string) SM2
- func (this SM2) FromPrivateKey(key []byte) SM2
- func (this SM2) FromPrivateKeyBytes(priByte []byte) SM2
- func (this SM2) FromPrivateKeyDBytes(DBytes []byte) SM2
- func (this SM2) FromPrivateKeyString(keyString string) SM2
- func (this SM2) FromPrivateKeyWithPassword(key []byte, password string) SM2
- func (this SM2) FromPublicKey(key []byte) SM2
- func (this SM2) FromPublicKeyString(keyString string) SM2
- func (this SM2) FromPublicKeyXYBytes(XBytes, YBytes []byte) SM2
- func (this SM2) FromString(data string) SM2
- func (this SM2) GenerateKey() SM2
- func (this SM2) GetData() []byte
- func (this SM2) GetError() error
- func (this SM2) GetKeyData() []byte
- func (this SM2) GetParedData() []byte
- func (this SM2) GetPrivateKey() *sm2.PrivateKey
- func (this SM2) GetPrivateKeyCurve() elliptic.Curve
- func (this SM2) GetPrivateKeyD() *big.Int
- func (this SM2) GetPrivateKeyX() *big.Int
- func (this SM2) GetPrivateKeyY() *big.Int
- func (this SM2) GetPublicKey() *sm2.PublicKey
- func (this SM2) GetPublicKeyCurve() elliptic.Curve
- func (this SM2) GetPublicKeyX() *big.Int
- func (this SM2) GetPublicKeyY() *big.Int
- func (this SM2) GetVeryed() bool
- func (this SM2) ParsePrivateKeyFromPEM(key []byte) (*sm2.PrivateKey, error)
- func (this SM2) ParsePrivateKeyFromPEMWithPassword(key []byte, password string) (*sm2.PrivateKey, error)
- func (this SM2) ParsePublicKeyFromPEM(key []byte) (*sm2.PublicKey, error)
- func (this SM2) Sign() SM2
- func (this SM2) SignAsn1(uid []byte) SM2
- func (this SM2) SignHex(uid []byte) SM2
- func (this SM2) ToBase64String() string
- func (this SM2) ToBytes() []byte
- func (this SM2) ToHexString() string
- func (this SM2) ToKeyBytes() []byte
- func (this SM2) ToKeyString() string
- func (this SM2) ToString() string
- func (this SM2) ToVeryed() bool
- func (this SM2) VerifyAsn1(data []byte, uid []byte) SM2
- func (this SM2) VerifyHex(data []byte, uid []byte) SM2
- func (this SM2) Very(data []byte) SM2
- func (this SM2) WithData(data []byte) SM2
- func (this SM2) WithError(err error) SM2
- func (this SM2) WithParedData(data []byte) SM2
- func (this SM2) WithPrivateKey(data *sm2.PrivateKey) SM2
- func (this SM2) WithPublicKey(data *sm2.PublicKey) SM2
Constants ¶
const PBKDF2Iterations = 10000
PBKDF2Iterations is the default number of iterations for PBKDF2, 100k iterations. Nist recommends at least 10k, 1Passsword uses 100k.
const PBKDF2SaltSize = 16
PBKDF2SaltSize is the default size of the salt for PBKDF2, 128-bit salt.
Variables ¶
var ( ErrNotECPublicKey = errors.New("key is not a valid ECDSA public key") ErrNotECPrivateKey = errors.New("key is not a valid ECDSA private key") )
var ( ErrNotEdPrivateKey = errors.New("key is not a valid Ed25519 private key") ErrNotEdPublicKey = errors.New("key is not a valid Ed25519 public key") )
var ( ErrDataToLarge = errors.New("message too long for RSA public key size") ErrDataLen = errors.New("data length error") ErrDataBroken = errors.New("data broken, first byte is not zero") ErrKeyPairDismatch = errors.New("data is not encrypted by the private key") ErrDecryption = errors.New("decryption error") )
var ( ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key") ErrNotRSAPrivateKey = errors.New("key is not a valid RSA private key") ErrNotRSAPublicKey = errors.New("key is not a valid RSA public key") )
var ( // 创建私钥默认可用选项 // HMACHash 目前支持 SHA256 和 SHA1 Youmark_AES128CBC_SHA256 = youmarkPkcs8.Opts{ Cipher: youmarkPkcs8.AES128CBC, KDFOpts: youmarkPkcs8.PBKDF2Opts{ SaltSize: 8, IterationCount: 2048, HMACHash: crypto.SHA256, }, } Youmark_AES192CBC_SHA256 = youmarkPkcs8.Opts{ Cipher: youmarkPkcs8.AES192CBC, KDFOpts: youmarkPkcs8.PBKDF2Opts{ SaltSize: 8, IterationCount: 1000, HMACHash: crypto.SHA256, }, } Youmark_AES256CBC_SHA256 = youmarkPkcs8.Opts{ Cipher: youmarkPkcs8.AES256CBC, KDFOpts: youmarkPkcs8.PBKDF2Opts{ SaltSize: 16, IterationCount: 2000, HMACHash: crypto.SHA256, }, } Youmark_AES128GCM_SHA256 = youmarkPkcs8.Opts{ Cipher: youmarkPkcs8.AES128GCM, KDFOpts: youmarkPkcs8.PBKDF2Opts{ SaltSize: 8, IterationCount: 2048, HMACHash: crypto.SHA256, }, } Youmark_AES192GCM_SHA256 = youmarkPkcs8.Opts{ Cipher: youmarkPkcs8.AES192GCM, KDFOpts: youmarkPkcs8.PBKDF2Opts{ SaltSize: 8, IterationCount: 10000, HMACHash: crypto.SHA256, }, } Youmark_AES256GCM_SHA256 = youmarkPkcs8.Opts{ Cipher: youmarkPkcs8.AES256GCM, KDFOpts: youmarkPkcs8.PBKDF2Opts{ SaltSize: 16, IterationCount: 16, HMACHash: crypto.SHA256, }, } Youmark_TripleDESCBC_SHA1 = youmarkPkcs8.Opts{ Cipher: youmarkPkcs8.TripleDESCBC, KDFOpts: youmarkPkcs8.PBKDF2Opts{ SaltSize: 16, IterationCount: 16, HMACHash: crypto.SHA1, }, } Youmark_AES256CBC_Scrypt = youmarkPkcs8.Opts{ Cipher: youmarkPkcs8.AES256CBC, KDFOpts: youmarkPkcs8.ScryptOpts{ CostParameter: 1 << 2, BlockSize: 8, ParallelizationParameter: 1, SaltSize: 16, }, } )
var DefaultOpts = &Opts{ SaltSize: PBKDF2SaltSize, IterationCount: PBKDF2Iterations, HMACHash: "SHA256", }
默认配置
var PEMCiphers = map[string]x509.PEMCipher{ "DESCBC": x509.PEMCipherDES, "DESEDE3CBC": x509.PEMCipher3DES, "AES128CBC": x509.PEMCipherAES128, "AES192CBC": x509.PEMCipherAES192, "AES256CBC": x509.PEMCipherAES256, }
pem 加密方式
Functions ¶
func DecryptPEMBlock ¶
解出 PEM 块
func DecryptPKCS8PrivateKey ¶
解出 PKCS8 密钥 加密方式: AES-128-CBC | AES-192-CBC | AES-256-CBC | DES | 3DES
Types ¶
type Cryptobin ¶
type Cryptobin struct { // 错误 Error error // contains filtered or unexported fields }
*
- 对称加密 *
- @create 2022-3-19
- @author deatil
func (Cryptobin) AesECBDecrypt ¶
func (Cryptobin) AesECBEncrypt ¶
func (Cryptobin) AesECBGenerateKey ¶
func (Cryptobin) Chacha20poly1305 ¶ added in v1.0.2
Chacha20poly1305 nonce is 12 bytes
func (Cryptobin) CipherBlock ¶
Cipher
func (Cryptobin) FromBase64String ¶
Base64
func (Cryptobin) FuncDecrypt ¶ added in v1.0.1006
方法解密
func (Cryptobin) FuncEncrypt ¶ added in v1.0.1006
方法加密
func (Cryptobin) GetOneConfig ¶ added in v1.0.3
获取一个配置
func (Cryptobin) ISO10126Padding ¶ added in v1.0.3
ISO10126 补码
func (Cryptobin) ISO7816_4Padding ¶ added in v1.0.3
ISO7816_4 补码
func (Cryptobin) PKCS1Padding ¶ added in v1.0.3
PKCS1 补码
func (Cryptobin) RsaDecrypt ¶
RSA 私钥解密 pkcs8 带密码不支持其他工具生成的密钥
func (Cryptobin) RsaOAEPDecrypt ¶ added in v1.0.1006
RSA OAEP 私钥解密 pkcs8 带密码不支持其他工具生成的密钥 typ 为 hash.defaultHashes 对应数据
func (Cryptobin) RsaOAEPEncrypt ¶ added in v1.0.1006
RSA OAEP 公钥加密 typ 为 hash.defaultHashes 对应数据
func (Cryptobin) RsaPrikeyEncrypt ¶
RSA 私钥加密 pkcs8 带密码不支持其他工具生成的密钥
func (Cryptobin) SM2Decrypt ¶ added in v1.0.3
SM2 私钥解密
func (Cryptobin) WithMultiple ¶ added in v1.0.1006
加密类型
func (Cryptobin) WithOneConfig ¶ added in v1.0.3
设置一个配置
func (Cryptobin) X923Padding ¶ added in v1.0.3
X923 补码
type Ecdsa ¶
type Ecdsa struct { // 错误 Error error // contains filtered or unexported fields }
*
- Ecdsa *
- @create 2022-4-3
- @author deatil
func EcdsaGenerateKey ¶
生成密钥 可选 [P521 | P384 | P256 | P224]
func (Ecdsa) FromPrivateKeyBytes ¶ added in v1.0.1005
明文私钥生成私钥结构体
func (Ecdsa) FromPrivateKeyDBytes ¶ added in v1.0.1006
私钥字符,必须先添加公钥
func (Ecdsa) FromPrivateKeyString ¶ added in v1.0.1005
私钥字符,必须先添加公钥 (hexStringD)
func (Ecdsa) FromPublicKeyString ¶ added in v1.0.1005
公钥字符 (hexStringX + hexStringY)
func (Ecdsa) FromPublicKeyXYBytes ¶ added in v1.0.1005
公钥字符对
func (Ecdsa) GetPrivateKeyCurve ¶ added in v1.0.1005
获取 PrivateKeyCurve
func (Ecdsa) GetPrivateKeyD ¶ added in v1.0.1005
获取 PrivateKeyD privateKeyDHex := NewEncoding().HexEncode(GetPrivateKeyD().Bytes())
func (Ecdsa) GetPrivateKeyX ¶ added in v1.0.1005
获取 PrivateKeyX privateKeyXHex := NewEncoding().HexEncode(GetPrivateKeyX().Bytes())
func (Ecdsa) GetPrivateKeyY ¶ added in v1.0.1005
获取 PrivateKeyY privateKeyYHex := NewEncoding().HexEncode(GetPrivateKeyY().Bytes())
func (Ecdsa) GetPublicKeyCurve ¶ added in v1.0.1005
获取 PublicKeyCurve
func (Ecdsa) GetPublicKeyX ¶ added in v1.0.1005
获取 PublicKeyX publicKeyXHex := NewEncoding().HexEncode(GetPublicKeyX().Bytes())
func (Ecdsa) GetPublicKeyY ¶ added in v1.0.1005
获取 PublicKeyY publicKeyYHex := NewEncoding().HexEncode(GetPublicKeyY().Bytes())
func (Ecdsa) ParseECPrivateKeyFromPEM ¶
func (this Ecdsa) ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error)
解析私钥
func (Ecdsa) ParseECPublicKeyFromPEM ¶
解析公钥
func (Ecdsa) VerifyAsn1 ¶ added in v1.0.1007
公钥验证 使用原始数据[data]对比签名后数据
func (Ecdsa) WithPrivateKey ¶
func (this Ecdsa) WithPrivateKey(data *ecdsa.PrivateKey) Ecdsa
设置 PrivateKey
func (Ecdsa) WithPublicKey ¶
设置 PublicKey
type EdDSA ¶ added in v1.0.2
type EdDSA struct { // 错误 Error error // contains filtered or unexported fields }
*
- EdDSA *
- @create 2022-4-3
- @author deatil
func (EdDSA) FromBase64String ¶ added in v1.0.2
Base64
func (EdDSA) GetPrivateKey ¶ added in v1.0.2
func (this EdDSA) GetPrivateKey() ed25519.PrivateKey
获取 PrivateKey
func (EdDSA) GetPublicKey ¶ added in v1.0.2
获取 PublicKey
func (EdDSA) ParseEdPrivateKeyFromPEM ¶ added in v1.0.2
func (this EdDSA) ParseEdPrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error)
解析私钥
func (EdDSA) ParseEdPublicKeyFromPEM ¶ added in v1.0.2
解析公钥
func (EdDSA) WithParedData ¶ added in v1.0.2
设置 paredData
func (EdDSA) WithPrivateKey ¶ added in v1.0.2
func (this EdDSA) WithPrivateKey(data ed25519.PrivateKey) EdDSA
设置 PrivateKey
type Encoding ¶ added in v1.0.1005
type Encoding struct{}
*
- 编码 *
- @create 2022-4-17
- @author deatil
func (Encoding) Base64Decode ¶ added in v1.0.1005
Base64 解码
func (Encoding) Base64Encode ¶ added in v1.0.1005
Base64 编码
type Hash ¶ added in v1.0.1006
type Hash struct {
// contains filtered or unexported fields
}
*
- 摘要 *
- @create 2022-4-16
- @author deatil
func (Hash) AddCryptoHash ¶ added in v1.0.1006
添加
func (Hash) DataCryptoHash ¶ added in v1.0.1006
签名后数据
func (Hash) GetCryptoHash ¶ added in v1.0.1006
类型
func (Hash) WithCryptoHashs ¶ added in v1.0.1006
func (this Hash) WithCryptoHashs(hashes CryptoHashMap) Hash
覆盖 cryptoHashes
type Padding ¶ added in v1.0.3
type Padding struct{}
*
- 补码 *
- @create 2022-4-17
- @author deatil
func (Padding) ISO10126Padding ¶ added in v1.0.3
ISO10126Padding 填充至符合块大小的整数倍,填充值最后一个字节为填充的数量数,其他字节填充随机字节。
func (Padding) ISO10126UnPadding ¶ added in v1.0.3
func (Padding) ISO7816_4Padding ¶ added in v1.0.3
ISO7816_4Padding 填充至符合块大小的整数倍,填充值第一个字节为0x80,其他字节填0x00。
func (Padding) ISO7816_4UnPadding ¶ added in v1.0.3
func (Padding) PKCS1Padding ¶ added in v1.0.3
填充格式如下: Padding = 00 + BT + PS + 00 + D 00为固定字节 BT为处理模式 PS为填充字节,填充数量为k - 3 - D,k表示密钥长度, D表示原文长度。 PS的最小长度为8个字节。填充的值根据BT值来定: BT = 00时,填充全00 BT = 01时,填充全FF BT = 02时,随机填充,但不能为00。
func (Padding) PKCS1UnPadding ¶ added in v1.0.3
func (Padding) PKCS5Padding ¶ added in v1.0.3
PKCS7Padding的子集,块大小固定为8字节
func (Padding) PKCS5UnPadding ¶ added in v1.0.3
func (Padding) PKCS7Padding ¶ added in v1.0.3
明文补码算法 填充至符合块大小的整数倍,填充值为填充数量数
func (Padding) PKCS7UnPadding ¶ added in v1.0.3
明文减码算法
func (Padding) RandomBytes ¶ added in v1.0.3
随机字节
func (Padding) TBCPadding ¶ added in v1.0.3
TBCPadding(Trailling-Bit-Compliment) 填充至符合块大小的整数倍,原文最后一位为1时填充0x00,最后一位为0时填充0xFF。
func (Padding) TBCUnPadding ¶ added in v1.0.3
func (Padding) X923Padding ¶ added in v1.0.3
X923Padding 填充至符合块大小的整数倍,填充值最后一个字节为填充的数量数,其他字节填0
func (Padding) X923UnPadding ¶ added in v1.0.3
func (Padding) ZeroPadding ¶ added in v1.0.3
数据长度不对齐时使用0填充,否则不填充
func (Padding) ZeroUnPadding ¶ added in v1.0.3
type Rsa ¶
type Rsa struct { // 错误 Error error // contains filtered or unexported fields }
*
- Rsa 加密 *
- @create 2021-8-28
- @author deatil
func RsaFromPKCS1WithPassword ¶
Pkcs1WithPassword
func RsaFromPKCS8WithPassword ¶
Pkcs8WithPassword
func RsaFromPrivateKeyWithPassword ¶
私钥带密码
func RsaFromYoumarkPKCS8WithPassword ¶
设置私钥带密码
func (Rsa) CreatePKCS1WithPassword ¶
PKCS1 私钥带密码 CreatePKCS1WithPassword("123", "AES256CBC")
func (Rsa) CreatePKCS8WithPassword ¶
PKCS8 私钥带密码 CreatePKCS8WithPassword("123", "AES256CBC", "SHA256")
func (Rsa) CreateYoumarkPKCS8WithPassword ¶
func (this Rsa) CreateYoumarkPKCS8WithPassword(password string, opt ...youmarkPkcs8.Opts) Rsa
创建私钥带密码
func (Rsa) FromPKCS1WithPassword ¶
Pkcs1WithPassword
func (Rsa) FromPKCS8WithPassword ¶
Pkcs8WithPassword
func (Rsa) FromPrivateKeyWithPassword ¶
私钥带密码
func (Rsa) FromYoumarkPKCS8WithPassword ¶
设置私钥带密码
func (Rsa) GenerateKey ¶
生成密钥 bits = 512 | 1024 | 2048 | 4096
func (Rsa) PSSSign ¶ added in v1.0.2
func (this Rsa) PSSSign(opts ...rsa.PSSOptions) Rsa
私钥签名 常用为: PS256[SHA256] | PS384[SHA384] | PS512[SHA512]
func (Rsa) PSSVery ¶ added in v1.0.2
func (this Rsa) PSSVery(data []byte, opts ...rsa.PSSOptions) Rsa
公钥验证 使用原始数据[data]对比签名后数据
func (Rsa) ParseRSAPKCS8PrivateKeyFromPEMWithPassword ¶
func (this Rsa) ParseRSAPKCS8PrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error)
解析 PKCS8 带密码的私钥
func (Rsa) ParseRSAPrivateKeyFromPEM ¶
func (this Rsa) ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)
解析 PKCS1 / PKCS8 私钥
func (Rsa) ParseRSAPrivateKeyFromPEMWithPassword ¶
func (this Rsa) ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error)
解析 PKCS1 带密码的私钥
func (Rsa) ParseRSAPublicKeyFromPEM ¶
解析 PKCS1 / PKCS8 公钥
type SM2 ¶ added in v1.0.3
type SM2 struct { // 错误 Error error // contains filtered or unexported fields }
*
- 国密 SM2 加密 *
- @create 2022-4-16
- @author deatil
func SM2FromPrivateKeyWithPassword ¶ added in v1.0.3
私钥带密码
func (SM2) CreatePrivateKeyWithPassword ¶ added in v1.0.3
国密 PKCS8 私钥带密码
func (SM2) FromBase64String ¶ added in v1.0.3
Base64
func (SM2) FromPrivateKeyBytes ¶ added in v1.0.1005
明文私钥生成私钥结构体
func (SM2) FromPrivateKeyDBytes ¶ added in v1.0.1006
私钥字符,必须先添加公钥
func (SM2) FromPrivateKeyString ¶ added in v1.0.1005
私钥字符,必须先添加公钥 (hexStringD) private-key: 07e4********;
func (SM2) FromPrivateKeyWithPassword ¶ added in v1.0.3
私钥带密码
func (SM2) FromPublicKeyString ¶ added in v1.0.1005
公钥字符 (hexStringX + hexStringY) public-key: 047c********.
func (SM2) FromPublicKeyXYBytes ¶ added in v1.0.1005
公钥字符对
func (SM2) GetPrivateKey ¶ added in v1.0.3
func (this SM2) GetPrivateKey() *sm2.PrivateKey
获取 PrivateKey
func (SM2) GetPrivateKeyCurve ¶ added in v1.0.1005
获取 PrivateKeyCurve
func (SM2) GetPrivateKeyD ¶ added in v1.0.1005
获取 PrivateKeyD privateKeyDHex := NewEncoding().HexEncode(GetPrivateKeyD().Bytes())
func (SM2) GetPrivateKeyX ¶ added in v1.0.1005
获取 PrivateKeyX privateKeyXHex := NewEncoding().HexEncode(GetPrivateKeyX().Bytes())
func (SM2) GetPrivateKeyY ¶ added in v1.0.1005
获取 PrivateKeyY privateKeyYHex := NewEncoding().HexEncode(GetPrivateKeyY().Bytes())
func (SM2) GetPublicKey ¶ added in v1.0.3
获取 PublicKey
func (SM2) GetPublicKeyCurve ¶ added in v1.0.1005
获取 PublicKeyCurve
func (SM2) GetPublicKeyX ¶ added in v1.0.1005
获取 PublicKeyX publicKeyXHex := NewEncoding().HexEncode(GetPublicKeyX().Bytes())
func (SM2) GetPublicKeyY ¶ added in v1.0.1005
获取 PublicKeyY publicKeyYHex := NewEncoding().HexEncode(GetPublicKeyY().Bytes())
func (SM2) ParsePrivateKeyFromPEM ¶ added in v1.0.3
func (this SM2) ParsePrivateKeyFromPEM(key []byte) (*sm2.PrivateKey, error)
解析 SM2 PKCS8 私钥
func (SM2) ParsePrivateKeyFromPEMWithPassword ¶ added in v1.0.3
func (this SM2) ParsePrivateKeyFromPEMWithPassword(key []byte, password string) (*sm2.PrivateKey, error)
解析 SM2 PKCS8 私钥带密码
func (SM2) ParsePublicKeyFromPEM ¶ added in v1.0.3
解析 SM2 PKCS8 公钥
func (SM2) VerifyAsn1 ¶ added in v1.0.1007
公钥验证 使用原始数据[data]对比签名后数据
func (SM2) WithParedData ¶ added in v1.0.3
设置 paredData
func (SM2) WithPrivateKey ¶ added in v1.0.3
func (this SM2) WithPrivateKey(data *sm2.PrivateKey) SM2
设置 PrivateKey
Source Files ¶
- cryptobin.go
- ecdsa.go
- ecdsa_create.go
- ecdsa_from.go
- ecdsa_get.go
- ecdsa_helper.go
- ecdsa_parse.go
- ecdsa_sign.go
- ecdsa_to.go
- ecdsa_with.go
- eddsa.go
- eddsa_create.go
- eddsa_from.go
- eddsa_get.go
- eddsa_helper.go
- eddsa_parse.go
- eddsa_sign.go
- eddsa_to.go
- eddsa_with.go
- encoding.go
- encryption.go
- encryption_cipher.go
- encryption_guess.go
- encryption_rsa.go
- encryption_sm2.go
- from.go
- get.go
- hash.go
- helper.go
- padding.go
- rsa.go
- rsa_create.go
- rsa_encodingkey.go
- rsa_encryption.go
- rsa_from.go
- rsa_get.go
- rsa_helper.go
- rsa_parse.go
- rsa_pkcs8.go
- rsa_pss_sign.go
- rsa_sign.go
- rsa_to.go
- rsa_with.go
- rsa_youmark.go
- sm2.go
- sm2_create.go
- sm2_encryption.go
- sm2_from.go
- sm2_get.go
- sm2_helper.go
- sm2_parse.go
- sm2_sign.go
- sm2_to.go
- sm2_with.go
- special.go
- to.go
- use.go
- with.go