Documentation ¶
Overview ¶
Package cryptowrapper contains several cryptographic algorithms like AES, RSA, ECDH, HMAC, HKDF and PBKDF2
Index ¶
- func AESCBCDecrypt(key []byte, input []byte) ([]byte, error)
- func AESCBCDecryptWithMAC(key []byte, input []byte) ([]byte, error)
- func AESCBCEncrypt(key []byte, input []byte) ([]byte, error)
- func AESCBCEncryptWithMAC(key []byte, input []byte) ([]byte, error)
- func BytesToUUIDFormat(bytes []byte) string
- func DeriveKey(hash func() hash.Hash, weakKey []byte, salt []byte, info []byte, keySize int) ([]byte, error)
- func GenUUID() string
- func GenUUIDAlt() string
- func GenerateECDHKeyPair(rand io.Reader) (crypto.PrivateKey, crypto.PublicKey, error)
- func GenerateECDHSharedSecret(privKey crypto.PrivateKey, pubKey crypto.PublicKey) ([]byte, error)
- func GenerateRSAKey(bits int) (*rsa.PrivateKey, error)
- func HMACSHA256(key []byte, messages ...[]byte) []byte
- func MD5UUIDFormat(input ...[]byte) string
- func MarshalECDHPublicKey(p crypto.PublicKey) []byte
- func MarshalPrivateKey(priv *rsa.PrivateKey) ([]byte, error)
- func MarshalPublicKey(pub *rsa.PublicKey) ([]byte, error)
- func PBKDF2HMACSHA256(password, salt []byte, iter, keyLen int) []byte
- func RSADecrypt(priv *rsa.PrivateKey, ciphertext []byte, label []byte) ([]byte, error)
- func RSAEncrypt(pub *rsa.PublicKey, msg []byte, label []byte) ([]byte, error)
- func RSASign(priv *rsa.PrivateKey, message []byte) ([]byte, error)
- func RSAVerify(pub *rsa.PublicKey, message []byte, signiture []byte) error
- func RandBigInt(bits int) *big.Int
- func RandBytes(n int) []byte
- func UnMarshalPrivateKey(der []byte) (*rsa.PrivateKey, error)
- func UnMarshalPublicKey(der []byte) (pubKey *rsa.PublicKey, err error)
- func UnmarshalECDHPublicKey(data []byte) (crypto.PublicKey, bool)
- func ValidateUUID(UUID string, sanitize ...bool) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AESCBCDecrypt ¶
AESCBCDecrypt performs a AES decryption in CBC mode
func AESCBCDecryptWithMAC ¶
AESCBCDecryptWithMAC performs a AES dencryption in CBC mode with a MAC authentication
func AESCBCEncrypt ¶
AESCBCEncrypt performs a AES encryption in CBC mode
func AESCBCEncryptWithMAC ¶
AESCBCEncryptWithMAC performs a AES encryption in CBC mode with a MAC authentication
func BytesToUUIDFormat ¶
BytesToUUIDFormat converts a 16 bytes to UUID format
func DeriveKey ¶
func DeriveKey(hash func() hash.Hash, weakKey []byte, salt []byte, info []byte, keySize int) ([]byte, error)
DeriveKey derives two cryptographically strong secret keys from the weak key. salt and info can be nil. salt is recommended to be hash-length sized random info is recommended to independent from the weak key. keySize is the desired size for the derived key, its up to yourself to split it as multiple keys for usage.
func GenerateECDHKeyPair ¶
GenerateECDHKeyPair generates the ECDH key pair
func GenerateECDHSharedSecret ¶
GenerateECDHSharedSecret calculates a common secret using the private key and public key
func GenerateRSAKey ¶
func GenerateRSAKey(bits int) (*rsa.PrivateKey, error)
GenerateRSAKey generates the RSA private key
func HMACSHA256 ¶
HMACSHA256 generates the HMAC for a message given a key.
func MD5UUIDFormat ¶
MD5UUIDFormat gets the MD5 hash of the input content and convert to UUID Format
func MarshalECDHPublicKey ¶
MarshalECDHPublicKey marshals the public key into byte array
func MarshalPrivateKey ¶
func MarshalPrivateKey(priv *rsa.PrivateKey) ([]byte, error)
MarshalPrivateKey marshals private key into ANS.1 DER bytes (PKSC#1 scheme)
func MarshalPublicKey ¶
MarshalPublicKey marshals public key into ANS.1 DER bytes (PKSC#1 scheme)
func PBKDF2HMACSHA256 ¶
PBKDF2HMACSHA256 derives a key for a given password
func RSADecrypt ¶
RSADecrypt decrypts the given cipher text with the private key
func RSAEncrypt ¶
RSAEncrypt encrypts the given message with the public key
func RSASign ¶
func RSASign(priv *rsa.PrivateKey, message []byte) ([]byte, error)
RSASign signs the given message with the private key.
func RandBigInt ¶
RandBigInt generates and return a bigInt 'bits' bits in length
func UnMarshalPrivateKey ¶
func UnMarshalPrivateKey(der []byte) (*rsa.PrivateKey, error)
UnMarshalPrivateKey unmarshals ANS.1 DER bytes back to private key
func UnMarshalPublicKey ¶
UnMarshalPublicKey unmarshals ANS.1 DER bytes back to public key
func UnmarshalECDHPublicKey ¶
UnmarshalECDHPublicKey unmarshals byte array into public key
Types ¶
This section is empty.