kmscrypto

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesGcmDecrypt

func AesGcmDecrypt(key, ciphertext, additionalData []byte) (plaintext []byte, err error)

AesGcmDecrypt similar to AesGcmDecryptWithNonce, but ciphertext is nonce-contained.

func AesGcmDecryptWithNonce

func AesGcmDecryptWithNonce(key, ciphertext, nonce, additionalData []byte) (plaintext []byte, err error)

AesGcmDecryptWithNonce takes an decryption key, a ciphertext and the corresponding nonce and decrypts it with AES256 in GCM mode. Returns the plaintext string.

func AesGcmEncrypt

func AesGcmEncrypt(key, plaintext, additionalData []byte) (ciphertext []byte, err error)

AesGcmEncrypt similar with AesGcmEncryptWithNonce, return nonce-contained ciphertext. Use AesGcmDecrypt to decrypt.

func AesGcmEncryptWithNonce

func AesGcmEncryptWithNonce(key, plaintext, additionalData []byte) (ciphertext, nonce []byte, err error)

AesGcmEncryptWithNonce takes an encryption key and a plaintext string and encrypts it with AES256 in GCM mode, which provides authenticated encryption. Returns the ciphertext and the used nonce.

func DecodeString

func DecodeString(data string, encodedType Encode) ([]byte, error)

DecodeString decodes string data to bytes in designed encoded type

func EncodeToString

func EncodeToString(data []byte, encodeType Encode) (string, error)

EncodeToString encodes data to string with encode type

func GenRsaKey

func GenRsaKey(bits int) ([]byte, []byte, error)

GenRsaKey return publicKey, privateKey, error

func GenerateAes256Key

func GenerateAes256Key() ([]byte, error)

GenerateAes256Key generate 256-bit aes symmetric key.

func ParsePrivateKey

func ParsePrivateKey(privateKeyDecoded []byte, keyType Secret) (*rsa.PrivateKey, error)

ParsePrivateKey parses private key bytes to rsa privateKey

func PrefixAppend000Length

func PrefixAppend000Length(b []byte) ([]byte, error)

PrefixAppend000Length max byte length is 999. []byte(b) -> 000[]byte(b)

func PrefixUnAppend000Length

func PrefixUnAppend000Length(b []byte) (under, remains []byte, err error)

PrefixUnAppend000Length 000[]byte(b)[]byte(a) -> []byte(b), []byte(a)

Types

type Encode

type Encode uint

Encode defines the type of bytes encoded to string

const (
	String Encode = iota
	HEX
	Base64
)

type RSACrypt

type RSACrypt struct {
	// contains filtered or unexported fields
}

func NewRSACrypt

func NewRSACrypt(secretInfo RSASecret) *RSACrypt

NewRSACrypt init with the RSA secret info

func (*RSACrypt) Decrypt

func (rc *RSACrypt) Decrypt(src string, srcType Encode) (dst string, err error)

Decrypt decrypts a plaintext using private key src the encrypted data with public key srcType the encoded type of encrypted data ,such as Base64,HEX

func (*RSACrypt) Encrypt

func (rc *RSACrypt) Encrypt(src string, outputDataType Encode) (dst string, err error)

Encrypt encrypts the given message with public key src the original data outputDataType the encoded type of encrypted data ,such as Base64,HEX

type RSASecret

type RSASecret struct {
	PublicKey          string
	PublicKeyDataType  Encode
	PrivateKey         string
	PrivateKeyDataType Encode
	PrivateKeyType     Secret
}

type Secret

type Secret uint

Secret defines the private key type

const (
	PKCS1 Secret = iota
	PKCS8
)

Jump to

Keyboard shortcuts

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