Documentation ¶
Index ¶
- Variables
- func AesDecrypt(cipherText, key []byte) (plantText []byte, err error)
- func AesEncrypt(plainText, key []byte) []byte
- func Base64Decode(input string) (data []byte, err error)
- func Base64Encode(input []byte) string
- func Base64UrlDecode(input string) (data []byte, err error)
- func Base64UrlEncode(input []byte) string
- func BigMax(x, y *big.Int) *big.Int
- func BigMin(x, y *big.Int) *big.Int
- func BigPow(a, b int64) *big.Int
- func Byte(bigint *big.Int, padlength, n int) byte
- func EccDecrypt(priv *ecdsa.PrivateKey, pub *ecdsa.PublicKey, cipherText []byte, salt ...byte) ([]byte, error)
- func EccEncrypt(priv *ecdsa.PrivateKey, pub *ecdsa.PublicKey, plantText []byte, salt ...byte) []byte
- func Exp(base, exponent *big.Int) *big.Int
- func FirstBitSet(v *big.Int) int
- func FromECDSA(priv *ecdsa.PrivateKey) []byte
- func FromECDSAPub(pub *ecdsa.PublicKey) []byte
- func FromsSm2Pub(pub *sm2.PublicKey) []byte
- func GenerateKey(r io.Reader) (prk *ecdsa.PrivateKey, err error)
- func GenerateRandomBytes(length int) ([]byte, error)
- func GenerateSharedSecret(priv crypto.PrivateKey, pub crypto.PublicKey, salt ...byte) ([]byte, error)
- func GetHasher(name string) hash
- func GetRandomString(n int, alphabets ...byte) string
- func GmHashKey(input []byte, keylen int) (key []byte)
- func GzipDecode(in []byte) (out []byte, err error)
- func GzipEncode(in []byte) (out []byte, err error)
- func Hash32(password, salt []byte) []byte
- func HashArgon(input, salt []byte, keylen uint32) (key []byte)
- func HashFile(filename string) (bs []byte, err error)
- func HashKey(input []byte, keylen int) (key []byte)
- func HashReader(file io.Reader) (bs []byte, err error)
- func HashSha(input, salt []byte, keylen int) (key []byte)
- func HexDecode(input string) []byte
- func HexEncode(input []byte) string
- func JsDecode(gmPriv *sm2.PrivateKey, eccPriv *ecdsa.PrivateKey, opt *JsDecodeHelper) (plainText string, err error)
- func JsEncode(gmPriv *sm2.PrivateKey, eccPriv *ecdsa.PrivateKey, gmPub *sm2.PublicKey, ...) (result map[string]string)
- func M(privKey *ecdsa.PrivateKey)
- func MakeKeyWithKey(key []byte) (prk *ecdsa.PrivateKey, err error)
- func MakeSm2KeyWithKey(key []byte) (prk *sm2.PrivateKey, err error)
- func MustParseBig256(s string) *big.Int
- func NewKey() (prk *ecdsa.PrivateKey, err error)
- func NewKeyWithKey(key []byte) (prk *ecdsa.PrivateKey)
- func NewSm2Key() (prk *sm2.PrivateKey, err error)
- func NewSm2KeyWithKey(key []byte) (prk *sm2.PrivateKey)
- func P256Sm2() elliptic.Curve
- func P521() elliptic.Curve
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func Padding(ciphertext []byte, blockSize int) []byte
- func ParseBig256(s string) (*big.Int, bool)
- func ReadBits(bigint *big.Int, buf []byte)
- func SecretboxDecrypt(input []byte, key []byte) (plantText []byte, err error)
- func SecretboxEncrypt(input []byte, key []byte) []byte
- func Sha1(input []byte) []byte
- func Sha256(input []byte) []byte
- func Sha512(input []byte) []byte
- func Sign(priv *ecdsa.PrivateKey, pt []byte) (sign []byte, err error)
- func Sign2(signer c.Signer, pt []byte, opts c.SignerOpts) (sign []byte, err error)
- func SignVer(pub *ecdsa.PublicKey, pt, sign []byte) (ok bool)
- func Sm2Decrypt(priv *sm2.PrivateKey, pub *sm2.PublicKey, cipherText []byte, salt ...byte) ([]byte, error)
- func Sm2Encrypt(priv *sm2.PrivateKey, pub *sm2.PublicKey, plainText []byte, salt ...byte) []byte
- func Sm2GenerateKey(r io.Reader) (*sm2.PrivateKey, error)
- func Sm4Decrypt(cipherText, key []byte) (plantText []byte, err error)
- func Sm4Encrypt(plainText, key []byte) []byte
- func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
- func ToECDSAPub(pub []byte) *ecdsa.PublicKey
- func ToSm2Pub(pub []byte) *sm2.PublicKey
- func U256(x *big.Int) *big.Int
- func UnPadding(origData []byte) []byte
- type HexOrDecimal256
- type JsDecodeHelper
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadParameters = errors.New("哈希参数格式错误") ErrIncompatibleVersion = errors.New("版本不兼容") ErrInvalidHash = errors.New("编码哈希的格式不正确") )
var ( MaxBig256 = new(big.Int).Set(tt256m1) MaxBig63 = new(big.Int).Sub(tt63, big.NewInt(1)) )
Various big integer limit values.
Functions ¶
func AesDecrypt ¶
func AesEncrypt ¶
func Byte ¶
Byte returns the byte at position n, with the supplied padlength in Little-Endian encoding. n==0 returns the MSB Example: bigint '5', padlength 32, n=31 => 5
func EccDecrypt ¶
func EccEncrypt ¶
func Exp ¶
Exp implements exponentiation by squaring. Exp returns a newly-allocated big integer and does not change base or exponent. The result is truncated to 256 bits.
Courtesy @karalabe and @chfast
func FirstBitSet ¶
FirstBitSet returns the index of the first 1 bit in v, counting from LSB.
func FromsSm2Pub ¶
func GenerateKey ¶
func GenerateKey(r io.Reader) (prk *ecdsa.PrivateKey, err error)
GenerateKey 生成密钥对
func GenerateRandomBytes ¶
GenerateRandomBytes Generate n number of random bytes
func GenerateSharedSecret ¶
func GenerateSharedSecret(priv crypto.PrivateKey, pub crypto.PublicKey, salt ...byte) ([]byte, error)
GenerateSharedSecret 生成共享密钥
func GetRandomString ¶
func GzipDecode ¶
func GzipEncode ¶
func JsDecode ¶
func JsDecode(gmPriv *sm2.PrivateKey, eccPriv *ecdsa.PrivateKey, opt *JsDecodeHelper) (plainText string, err error)
func M ¶
func M(privKey *ecdsa.PrivateKey)
func MakeKeyWithKey ¶
func MakeKeyWithKey(key []byte) (prk *ecdsa.PrivateKey, err error)
MakeKeyWithKey 指定特征后直接生成密钥
func MakeSm2KeyWithKey ¶
func MakeSm2KeyWithKey(key []byte) (prk *sm2.PrivateKey, err error)
MakeKeyWithKey 指定特征后直接生成密钥
func MustParseBig256 ¶
MustParseBig256 parses s as a 256 bit big integer and panics if the string is invalid.
func NewKeyWithKey ¶
func NewKeyWithKey(key []byte) (prk *ecdsa.PrivateKey)
NewKeyWithKey 指定特征SHA512后生成密钥
func NewSm2KeyWithKey ¶
func NewSm2KeyWithKey(key []byte) (prk *sm2.PrivateKey)
NewKeyWithKey 指定特征SHA512后生成密钥
func PaddedBigBytes ¶
PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.
func ParseBig256 ¶
ParseBig256 parses s as a 256 bit integer in decimal or hexadecimal syntax. Leading zeros are accepted. The empty string parses as zero.
func ReadBits ¶
ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.
func SecretboxDecrypt ¶
Decrypt Decrypt (authenticated) a series of bytes given the secret key
func SecretboxEncrypt ¶
func Sm2Decrypt ¶
func Sm2Encrypt ¶
func Sm2GenerateKey ¶
func Sm2GenerateKey(r io.Reader) (*sm2.PrivateKey, error)
func Sm4Decrypt ¶
func Sm4Encrypt ¶
Types ¶
type HexOrDecimal256 ¶
HexOrDecimal256 marshals big.Int as hex or decimal.
func (*HexOrDecimal256) MarshalText ¶
func (i *HexOrDecimal256) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (*HexOrDecimal256) UnmarshalText ¶
func (i *HexOrDecimal256) UnmarshalText(input []byte) error
UnmarshalText implements encoding.TextUnmarshaler.