cryptography

package
v0.0.0-...-4d93f28 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: LGPL-3.0 Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AES_256_CBC_RandomIV

func AES_256_CBC_RandomIV() ([]byte, error)

Returns a random IV (16 bytes = aes.BlockSize)

func AES_256_CBC_decrypt

func AES_256_CBC_decrypt(ciphertext []byte, key []byte) ([]byte, error)

Inspired by the example at: https://golang.org/pkg/crypto/cipher/#NewCBCDecrypter

func AES_256_CBC_decrypt_with_padding

func AES_256_CBC_decrypt_with_padding(ciphertext []byte, key []byte) ([]byte, error)

Calls AES_256_CBC_decrypt() and returns the result without the PKCS7 padding.

func AES_256_CBC_encrypt

func AES_256_CBC_encrypt(plaintext []byte, key []byte, iv []byte) ([]byte, error)

Inspired by the example at: https://golang.org/pkg/crypto/cipher/#NewCBCEncrypter

func AES_256_CBC_encrypt_with_padding

func AES_256_CBC_encrypt_with_padding(plaintext []byte, key []byte) ([]byte, error)

Calls AES_256_CBC_encrypt() with a randomly generated IV and appends the PKCS7 corresponding padding. See the return value of AES_256_CBC_encrypt().

func DecodeX509PrivateKeyRSA

func DecodeX509PrivateKeyRSA(key []byte) (*rsa.PrivateKey, error)

The following OpenSSL command will generate an appropriate 2048 bit RSA private key: "openssl genrsa -out my.key 2048".

func DecryptWithRSA_2048_with_AES_256_CBC

func DecryptWithRSA_2048_with_AES_256_CBC(ciphertext []byte, privKey *rsa.PrivateKey) ([]byte, error)

func EncryptWithRSA_2048_with_AES_256_CBC

func EncryptWithRSA_2048_with_AES_256_CBC(plaintext []byte, pubKey *rsa.PublicKey) ([]byte, error)

Encrypts the data with AES-256-CBC with a random key and then encrypts the random AES key with a RSA 2048 bit public key. The key is then appended as the prefix of the ciphertext.

func PaddingPKCS7

func PaddingPKCS7(data []byte, size int) []byte

Returns the data with padding added to the end following the PKCS#7 (RFC 5652) guidelines.

func PaddingPKCS7Remove

func PaddingPKCS7Remove(data []byte) ([]byte, error)

Returns the data with the padding removed at the end following the PKCS#7 (RFC 5652) guidelines. Reverses what PaddingPKCS7 does.

func RSA_SHA256_signature

func RSA_SHA256_signature(data []byte, privKey *rsa.PrivateKey) (signature []byte, err error)

Creates a signature by hashing the data using SHA-256 then using the private RSA key to sign the message.

func RSA_SHA256_signature_verify

func RSA_SHA256_signature_verify(data []byte, pubKey *rsa.PublicKey, signature []byte) (success bool)

Verifies a signature by hashing the data using SHA-256 then using the public RSA key to check if the message was signed with the corresponding private RSA key (this function is meant to be used in conjunction with RSA_SHA256_signature(). Please do not call this function with an empty data/signature slice, because the response is undefined.

func RSA_decrypt

func RSA_decrypt(data []byte, privKey *rsa.PrivateKey) (plaintext []byte, err error)

Using the RSA private key we decrypt a slice of byte data that was encrypted using the corresponding RSA public key.

func RSA_encrypt

func RSA_encrypt(data []byte, pubKey *rsa.PublicKey) (ciphertext []byte, err error)

Using a RSA public key we encrypt a slice of byte data.

func RandomKey

func RandomKey(size uint) ([]byte, error)

Generate a cryptographically secure pseudorandom key. Size parameter should by in bytes.

func ReadPEMFile

func ReadPEMFile(path string) ([]byte, error)

inspired by: https://golang.org/pkg/io/ioutil/#ReadFile

Types

This section is empty.

Jump to

Keyboard shortcuts

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