Documentation
¶
Index ¶
- func Decrypt(pk *rsa.PrivateKey, cipherText string, label string) (string, error)
- func Encrypt(pk *rsa.PublicKey, clearText string, label string) (string, error)
- func GenerateKey(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)
- func PrivateKeyFromBytes(priv []byte) (*rsa.PrivateKey, error)
- func PrivateKeyToBytes(priv *rsa.PrivateKey) []byte
- func PublicKeyFromBytes(pub []byte) (*rsa.PublicKey, error)
- func PublicKeyToBytes(pub *rsa.PublicKey) ([]byte, error)
- func Sign(pk *rsa.PrivateKey, message string) (string, error)
- func ValidateSign(pk *rsa.PublicKey, message string, sign string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
Decrypt returns a decrypted text using RSA-OAEP algorithm.
Example:
// example data cipherText := "..." label := "some label" // load the private key privateKeyPem := `-----BEGIN RSA PRIVATE KEY-----...-----END RSA PRIVATE KEY-----` privateKey, _ := rsa.PrivateKeyFromPEM([]byte(privateKeyPem)) // decrypt the cipher text clearText, _ := rsa.Decrypt(privateKey, cipherText, label)
func Encrypt ¶
Encrypt returns a cipher text of the clear text using RSA-OAEP algorithm.
Example:
// example data clearText := "hello world" label := "some label" // load the private key publicKeyPem := `-----BEGIN RSA PUBLIC KEY-----...-----END RSA PUBLIC KEY-----` publicKey, _ := rsa.PublicKeyFromPEM([]byte(publicKeyPEM)) // encrypt the clear text cipherText, _ := rsa.Encrypt(publicKey, clearText, label)
func GenerateKey ¶
GenerateKey generates an RSA keypair of the given bit size.
func PrivateKeyFromBytes ¶
func PrivateKeyFromBytes(priv []byte) (*rsa.PrivateKey, error)
PrivateKeyFromBytes bytes to private key
func PrivateKeyToBytes ¶
func PrivateKeyToBytes(priv *rsa.PrivateKey) []byte
PrivateKeyToBytes private key to bytes
func PublicKeyFromBytes ¶
PublicKeyFromBytes bytes to public key
func PublicKeyToBytes ¶
PublicKeyToBytes public key to bytes
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.