Documentation ¶
Index ¶
- func AES_256_CBC_RandomIV() ([]byte, error)
- func AES_256_CBC_decrypt(ciphertext []byte, key []byte) ([]byte, error)
- func AES_256_CBC_decrypt_with_padding(ciphertext []byte, key []byte) ([]byte, error)
- func AES_256_CBC_encrypt(plaintext []byte, key []byte, iv []byte) ([]byte, error)
- func AES_256_CBC_encrypt_with_padding(plaintext []byte, key []byte) ([]byte, error)
- func DecodeX509PrivateKeyRSA(key []byte) (*rsa.PrivateKey, error)
- func DecodeX509PublicKeyRSA(key []byte) (*rsa.PublicKey, error)
- func DecryptWithRSA_2048_with_AES_256_CBC(ciphertext []byte, privKey *rsa.PrivateKey) ([]byte, error)
- func EncryptWithRSA_2048_with_AES_256_CBC(plaintext []byte, pubKey *rsa.PublicKey) ([]byte, error)
- func PaddingPKCS7(data []byte, size int) []byte
- func PaddingPKCS7Remove(data []byte) ([]byte, error)
- func RSA_SHA256_signature(data []byte, privKey *rsa.PrivateKey) (signature []byte, err error)
- func RSA_SHA256_signature_verify(data []byte, pubKey *rsa.PublicKey, signature []byte) (success bool)
- func RSA_decrypt(data []byte, privKey *rsa.PrivateKey) (plaintext []byte, err error)
- func RSA_encrypt(data []byte, pubKey *rsa.PublicKey) (ciphertext []byte, err error)
- func RandomKey(size uint) ([]byte, error)
- func ReadPEMFile(path string) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AES_256_CBC_RandomIV ¶
Returns a random IV (16 bytes = aes.BlockSize)
func AES_256_CBC_decrypt ¶
Inspired by the example at: https://golang.org/pkg/crypto/cipher/#NewCBCDecrypter
func AES_256_CBC_decrypt_with_padding ¶
Calls AES_256_CBC_decrypt() and returns the result without the PKCS7 padding.
func AES_256_CBC_encrypt ¶
Inspired by the example at: https://golang.org/pkg/crypto/cipher/#NewCBCEncrypter
func AES_256_CBC_encrypt_with_padding ¶
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 DecodeX509PublicKeyRSA ¶
inspired by: https://golang.org/pkg/crypto/x509/#ParsePKIXPublicKey
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 ¶
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 ¶
Returns the data with padding added to the end following the PKCS#7 (RFC 5652) guidelines.
func PaddingPKCS7Remove ¶
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 ¶
Using a RSA public key we encrypt a slice of byte data.
func RandomKey ¶
Generate a cryptographically secure pseudorandom key. Size parameter should by in bytes.
func ReadPEMFile ¶
inspired by: https://golang.org/pkg/io/ioutil/#ReadFile
Types ¶
This section is empty.