Documentation ¶
Index ¶
- func Fnv32HashCode(s string) uint32
- func Fnv32aHashCode(s string) uint32
- func Fnv64HashCode(s string) uint64
- func Fnv64aHashCode(s string) uint64
- func GenRSAKey(out io.Writer, bits int) error
- func Md5(s string) string
- func Sha1(dst string) string
- func Sha1WithSalt(dst string, salt string) string
- func Sha256(dst string) string
- func Sha256WithSalt(dst string, salt string) string
- func Sha512(dst string) string
- func Sha512WithSalt(dst string, salt string) string
- type AES
- func (x *AES) Decrypt(ciphertext any) (any, error)
- func (x *AES) DecryptWithBytes(cipherBuf []byte) ([]byte, error)
- func (x *AES) DecryptWithString(ciphertext string) (string, error)
- func (x *AES) Encrypt(plaintext any) (any, error)
- func (x *AES) EncryptWithBytes(plaintext []byte) ([]byte, error)
- func (x *AES) EncryptWithString(plaintext string) (string, error)
- func (x *AES) NewNonce() []byte
- func (x *AES) NewNonceStr() string
- type HexEncoder
- type OptFunc
- type RSA
- func (r *RSA) Decrypt(ciphertext any) (any, error)
- func (r *RSA) DecryptPKCS1v15(ciphertext []byte) ([]byte, error)
- func (r *RSA) DecryptWithBytes(ciphertext []byte) ([]byte, error)
- func (r *RSA) DecryptWithString(ciphertext string) (string, error)
- func (r *RSA) Encrypt(plaintext any) (any, error)
- func (r *RSA) EncryptPKCS1v15(msg []byte) ([]byte, error)
- func (r *RSA) EncryptWithBytes(msg []byte) ([]byte, error)
- func (r *RSA) EncryptWithString(plaintext string) (string, error)
- func (r *RSA) SetPrivateKey(private []byte) error
- func (r *RSA) SetPrivateKeyByBase64(privateStr string) error
- func (r *RSA) SetPublicKey(public []byte) error
- func (r *RSA) SetPublicKeyByBase64(publicStr string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fnv32HashCode ¶
func Fnv32aHashCode ¶
func Fnv64HashCode ¶
func Fnv64aHashCode ¶
func Sha1WithSalt ¶
func Sha256WithSalt ¶
func Sha512WithSalt ¶
Types ¶
type AES ¶
type AES struct { AdditionalData []byte FixedNonce []byte // contains filtered or unexported fields }
func (*AES) NewNonceStr ¶
type HexEncoder ¶
type HexEncoder struct{}
func (HexEncoder) DecodeString ¶
func (h HexEncoder) DecodeString(s string) ([]byte, error)
func (HexEncoder) EncodeToString ¶
func (h HexEncoder) EncodeToString(b []byte) string
type OptFunc ¶
type OptFunc func(c *AES)
func AESOptWithDataByte ¶
func AESOptWithEncoder ¶
func AESOptWithEncoder(i encoder) OptFunc
func AESOptWithFixedNonce ¶
AESOptWithFixedNonce sets the fixed nonce for the AES encryption. This setting enables the same string to be encrypted with the same result. This is needed in some business scenarios. However, it should be used with caution as it can lead to security vulnerabilities. If not sets this option will generate a new nonce for each encryption.
func AESOptWithNonceSize ¶
AESOptWithNonceSize sets the nonce size for the AES encryption. The default nonce size is 12 bytes, which is the recommended size. If you need to use a different nonce size, you can set it using this option. NOTE: If you set a fixed nonce, this setting will be invalid.
type RSA ¶
type RSA struct {
// contains filtered or unexported fields
}
func (*RSA) DecryptPKCS1v15 ¶
DecryptPKCS1v15 decrypts AdditionalData with private key
func (*RSA) DecryptWithBytes ¶
DecryptWithBytes decrypts AdditionalData with private key
func (*RSA) EncryptPKCS1v15 ¶
EncryptPKCS1v15 encrypts AdditionalData with public key
func (*RSA) EncryptWithBytes ¶
EncryptWithBytes encrypts AdditionalData with public key
func (*RSA) SetPrivateKey ¶
SetPrivateKey bytes to private key
func (*RSA) SetPrivateKeyByBase64 ¶
SetPrivateKeyByBase64 Get bytes AdditionalData by decoding base64 string
func (*RSA) SetPublicKey ¶
SetPublicKey bytes to public key
func (*RSA) SetPublicKeyByBase64 ¶
SetPublicKeyByBase64 Get bytes AdditionalData by decoding base64 string