Documentation ¶
Index ¶
- Variables
- func Decrypt(passphrase, ciphertext string) string
- func DecryptRaw(passphrase, salt, initializationVector, ciphertext []byte) ([]byte, error)
- func DecryptToBytes(passphrase, ciphertext string) []byte
- func DeriveKey(passphrase []byte, salt []byte) ([]byte, []byte)
- func Encrypt(passphrase, plaintext string) string
- func EncryptBytes(passphrase, plaintext []byte) string
- func ExportRsaPrivateKeyAsPemStr(privkey *rsa.PrivateKey) string
- func GenerateOTP(length int) (string, error)
- func GetDataHash(m interface{}) (*[32]byte, error)
- func LoadPemFile(filePath string) ([]byte, error)
- func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error)
- func RSACreatePairToPemFiles() (*string, *string, error)
- func RsaDecryptWithPrivateKey(ciphertext []byte, priv *rsa.PrivateKey) []byte
- func RsaEncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte
- func RsaEncodePublicKeyToPEM(rsaPublicKey *rsa.PublicKey) ([]byte, error)
- func RsaEncryptWithPublicKey(msg []byte, pub *rsa.PublicKey) ([]byte, error)
- func RsaGenerateAndStore(bitSize int, privateKeyFile, publicKeyFile string) (*rsa.PrivateKey, error)
- func RsaGeneratePrivateKey(bitSize int) (*rsa.PrivateKey, error)
- func RsaParsePrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)
- func RsaParsePublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)
- func SignRsaMessage(m interface{}, privateKey *rsa.PrivateKey) (*[]byte, error)
- func VerifyRsaMessage(m interface{}, publicKey *rsa.PublicKey, signature []byte) bool
- type ECDSA
- func (e *ECDSA) DecodeEcdsaPem(pemEncodedPriv []byte) error
- func (e *ECDSA) DecodeEcdsaPublicKeyPem(pemEncodedPub []byte) error
- func (e *ECDSA) EncodeEcdsaToPem() (string, string)
- func (e *ECDSA) GenerateAndEncodeEcdsaKeys() (string, string, error)
- func (e ECDSA) SignEcdsaMessage(m interface{}) (*[]byte, error)
- func (e ECDSA) VerifyEcdsaMessage(m interface{}, signature []byte) bool
- type EncryptResult
Constants ¶
This section is empty.
Variables ¶
var ( ErrKeyMustBePEMEncoded = errors.New(errors.ErrorGeneratingRsa, "invalid Key: Key must be a PEM encoded PKCS1 or PKCS8 key") ErrNotRSAPrivateKey = errors.New(errors.ErrorGeneratingRsa, "key is not a valid RSA private key") ErrNotRSAPublicKey = errors.New(errors.ErrorGeneratingRsa, "key is not a valid RSA public key") )
Functions ¶
func DecryptRaw ¶
func DecryptToBytes ¶
Decrypt decrypts ciphertext using the passphrase. The output is a byte array
func Encrypt ¶
Encrypt encrypts plain text using passphrase. Returns an Hex String containing Salt, IV and ciphertext.
func EncryptBytes ¶
Encrypt encrypts plain text using passphrase bytes. Returns an Hex String containing Salt, IV and ciphertext.
func ExportRsaPrivateKeyAsPemStr ¶
func ExportRsaPrivateKeyAsPemStr(privkey *rsa.PrivateKey) string
func GetDataHash ¶
func LoadPemFile ¶
Loads a Pemfile using the file path from file system
func ParseRsaPrivateKeyFromPemStr ¶
func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error)
func RSACreatePairToPemFiles ¶ added in v0.1.3
func RsaDecryptWithPrivateKey ¶
func RsaDecryptWithPrivateKey(ciphertext []byte, priv *rsa.PrivateKey) []byte
RsaDecryptWithPrivateKey decrypts data with private key
func RsaEncodePrivateKeyToPEM ¶
func RsaEncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte
RsaEncodePrivateKeyToPEM encodes Private Key from RSA to PEM format
func RsaEncodePublicKeyToPEM ¶
RsaEncodePublicKeyToPEM take a rsa.PublicKey and return bytes suitable for writing to .pub file returns in the format "ssh-rsa ..."
func RsaEncryptWithPublicKey ¶
RsaEncryptWithPublicKey encrypts data with public key
func RsaGenerateAndStore ¶
func RsaGenerateAndStore(bitSize int, privateKeyFile, publicKeyFile string) (*rsa.PrivateKey, error)
func RsaGeneratePrivateKey ¶
func RsaGeneratePrivateKey(bitSize int) (*rsa.PrivateKey, error)
RsaGeneratePrivateKey creates a RSA Private Key of specified byte size
func RsaParsePrivateKeyFromPEM ¶
func RsaParsePrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)
Parse PEM encoded PKCS1 or PKCS8 private key
func RsaParsePublicKeyFromPEM ¶
Parse PEM encoded PKCS1 or PKCS8 public key
func SignRsaMessage ¶
func SignRsaMessage(m interface{}, privateKey *rsa.PrivateKey) (*[]byte, error)
Signs a message (for example an struct) with the given RSA private key
Input: The message to sign, it must be serializable to a JSON the RSA Privatekey to sign the message Output: The signature as byte array the error if there is any error getting the Hash or the signature
func VerifyRsaMessage ¶
Verifies a message (for example an struct) signature using RSA public key
Input: The message to verify, it must be serializable to a JSON. Remember to remove the signature from message if you have included it in a field the RSA Public key to verify the message The signature as byte array Output: true if the signature can be verified with the message or false elsewhere.
Types ¶
type ECDSA ¶
type ECDSA struct { PrivateKey *ecdsa.PrivateKey PublicKey *ecdsa.PublicKey }
func (*ECDSA) DecodeEcdsaPem ¶
Decodes ECDSA Pem encoded private key
func (*ECDSA) DecodeEcdsaPublicKeyPem ¶
Decodes ECDSA Pem encoded public key
func (*ECDSA) EncodeEcdsaToPem ¶
Encodes Ecdsa private and public keys to PEM
func (*ECDSA) GenerateAndEncodeEcdsaKeys ¶
Generates ECDSA pair and encodes them to pem
func (ECDSA) SignEcdsaMessage ¶
Signs a message (for example an struct) with the given RSA private key
Input: The message to sign, it must be serializable to a JSON the RSA Privatekey to sign the message Output: The signature as byte array the error if there is any error getting the Hash or the signature
func (ECDSA) VerifyEcdsaMessage ¶
Verifies a message (for example an struct) signature using RSA public key
Input: The message to verify, it must be serializable to a JSON. Remember to remove the signature from message if you have included it in a field the RSA Public key to verify the message The signature as byte array Output: true if the signature can be verified with the message or false elsewhere.
type EncryptResult ¶
func EncryptRaw ¶
func EncryptRaw(passphrase, plaintext []byte, salt []byte, iv []byte) (*EncryptResult, error)
Encrypts the plain text using the passphrase and returns an EncryptResult struct containing the Salt, the Initialization Vector and the encrypted data. It is based on http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf, Section 8.2