Documentation ¶
Index ¶
- Constants
- func DecryptWithBase64(str string) (string, error)
- func EncryptWithBase64(str string) (string, error)
- func GenTopicKey() string
- func RandKey(n int) string
- type AES
- type AsymKeys
- type Decrypto
- type Encrypto
- type RSA
- func (a *RSA) Decrypt(ciphertext []byte, key []byte) ([]byte, error)
- func (a *RSA) DecryptWithDefaultKey(ciphertext []byte) ([]byte, error)
- func (a *RSA) Encrypt(plaintext []byte, key []byte) ([]byte, error)
- func (a *RSA) EncryptWithDefaultKey(plaintext []byte) ([]byte, error)
- func (a *RSA) GetPrivateKey() ([]byte, error)
- func (a *RSA) GetPublicKey() ([]byte, error)
- type RSAKeyPair
- func (keys *RSAKeyPair) DecodeToken(tokenStr string) (*jwt.Token, error)
- func (keys *RSAKeyPair) GenerateToken(userSubject string) (string, error)
- func (keys *RSAKeyPair) GetTokenRemainingValidity(timestamp interface{}) int
- func (keys *RSAKeyPair) GetTokenSubject(tokenStr string) (string, error)
- func (keys *RSAKeyPair) VerifyTokenSubject(tokenStr, subject string) (bool, error)
Constants ¶
const ( // AesAlgo enum for AES AesAlgo int = iota // RsaAlgo enum for RSA RsaAlgo )
Variables ¶
This section is empty.
Functions ¶
func DecryptWithBase64 ¶
DecryptWithBase64 a 64encoded string with the default key AES
func EncryptWithBase64 ¶
EncryptWithBase64 encrypts a string with AES default key and returns 64encoded string
Types ¶
type AES ¶
type AES struct {
DefaultSalt string
}
AES struct implementation including encryption and decryption
func (*AES) DecryptWithDefaultKey ¶
DecryptWithDefaultKey decrypts with a default key
type AsymKeys ¶
type AsymKeys interface {
// contains filtered or unexported methods
}
AsymKeys asymmetric keys
type Decrypto ¶
type Decrypto interface {
// contains filtered or unexported methods
}
Decrypto decryption
type Encrypto ¶
type Encrypto interface {
// contains filtered or unexported methods
}
Encrypto encryption
type RSA ¶
type RSA struct { MyPrivateKey *rsa.PrivateKey MyPublicKey *rsa.PublicKey }
RSA struct implementation including encryption and decryption
func NewRSAWithKeys ¶
NewRSAWithKeys with private and public keys
func (*RSA) DecryptWithDefaultKey ¶
DecryptWithDefaultKey decrypts with a default RSA key
func (*RSA) EncryptWithDefaultKey ¶
EncryptWithDefaultKey encrypts with a default RSA key
func (*RSA) GetPrivateKey ¶
GetPrivateKey gets the private RSA key
func (*RSA) GetPublicKey ¶
GetPublicKey gets the public RSA key
type RSAKeyPair ¶
type RSAKeyPair struct { PrivateKey *rsa.PrivateKey PublicKey *rsa.PublicKey }
RSAKeyPair for JWT token sign and verification
func NewRSAKeyPair ¶
func NewRSAKeyPair(privateKeyPath, publicKeyPath string) *RSAKeyPair
NewRSAKeyPair creates a pair of RSA key for JWT token sign and verification
func (*RSAKeyPair) DecodeToken ¶
func (keys *RSAKeyPair) DecodeToken(tokenStr string) (*jwt.Token, error)
DecodeToken decodes a token string
func (*RSAKeyPair) GenerateToken ¶
func (keys *RSAKeyPair) GenerateToken(userSubject string) (string, error)
GenerateToken generates token with user defined subject
func (*RSAKeyPair) GetTokenRemainingValidity ¶
func (keys *RSAKeyPair) GetTokenRemainingValidity(timestamp interface{}) int
GetTokenRemainingValidity is the remaining seconds before token expires
func (*RSAKeyPair) GetTokenSubject ¶
func (keys *RSAKeyPair) GetTokenSubject(tokenStr string) (string, error)
GetTokenSubject gets the subjects from a token
func (*RSAKeyPair) VerifyTokenSubject ¶
func (keys *RSAKeyPair) VerifyTokenSubject(tokenStr, subject string) (bool, error)
VerifyTokenSubject verifies a token string based on required matching subject