icrypto

package
v0.0.0-...-ec8dcbf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AesAlgo enum for AES
	AesAlgo int = iota
	// RsaAlgo enum for RSA
	RsaAlgo
)

Variables

This section is empty.

Functions

func DecryptWithBase64

func DecryptWithBase64(str string) (string, error)

DecryptWithBase64 a 64encoded string with the default key AES

func EncryptWithBase64

func EncryptWithBase64(str string) (string, error)

EncryptWithBase64 encrypts a string with AES default key and returns 64encoded string

func GenTopicKey

func GenTopicKey() string

GenTopicKey generates a random key in 24 char length.

func RandKey

func RandKey(n int) string

RandKey generates a random key in n length

Types

type AES

type AES struct {
	DefaultSalt string
}

AES struct implementation including encryption and decryption

func (*AES) Decrypt

func (a *AES) Decrypt(ciphertext []byte, key []byte) ([]byte, error)

Decrypt decrypts with asymmetric key

func (*AES) DecryptWithDefaultKey

func (a *AES) DecryptWithDefaultKey(plaintext []byte) ([]byte, error)

DecryptWithDefaultKey decrypts with a default key

func (*AES) Encrypt

func (a *AES) Encrypt(plaintext []byte, key []byte) ([]byte, error)

Encrypt encrypts with asymmetric key

func (*AES) EncryptWithDefaultKey

func (a *AES) EncryptWithDefaultKey(plaintext []byte) ([]byte, error)

EncryptWithDefaultKey encrypts 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 NewRSA

func NewRSA() (RSA, error)

NewRSA creates RSA keys pair

func NewRSAWithKeys

func NewRSAWithKeys(priv []byte, pub []byte) (RSA, error)

NewRSAWithKeys with private and public keys

func (*RSA) Decrypt

func (a *RSA) Decrypt(ciphertext []byte, key []byte) ([]byte, error)

Decrypt decrypts with RSA key

func (*RSA) DecryptWithDefaultKey

func (a *RSA) DecryptWithDefaultKey(ciphertext []byte) ([]byte, error)

DecryptWithDefaultKey decrypts with a default RSA key

func (*RSA) Encrypt

func (a *RSA) Encrypt(plaintext []byte, key []byte) ([]byte, error)

Encrypt encrypts with RSA key

func (*RSA) EncryptWithDefaultKey

func (a *RSA) EncryptWithDefaultKey(plaintext []byte) ([]byte, error)

EncryptWithDefaultKey encrypts with a default RSA key

func (*RSA) GetPrivateKey

func (a *RSA) GetPrivateKey() ([]byte, error)

GetPrivateKey gets the private RSA key

func (*RSA) GetPublicKey

func (a *RSA) GetPublicKey() ([]byte, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL