Documentation
¶
Overview ¶
Example ¶
priKey, pubKey, err := GenerateKeyPair(2048, PKCS8) if err != nil { log.Fatal(err) } src := []byte("trumanwong") dst, err := Encrypt(src, pubKey) if err != nil { log.Fatal(err) } dst, err = Decrypt(dst, priKey) if err != nil { log.Fatal(err) } fmt.Println(string(dst))
Output: trumanwong
Index ¶
- Constants
- func Decrypt(src, privateKey []byte) ([]byte, error)
- func Encrypt(src, publicKey []byte) (dst []byte, err error)
- func GenerateKeyPair(bits int, format keyFormat) (privateKey, publicKey []byte, err error)
- func Sign(src []byte, privateKey []byte, hash crypto.Hash) ([]byte, error)
- func Verify(src, sign, publicKey []byte, hash crypto.Hash) error
Examples ¶
Constants ¶
View Source
const ( PKCS1 keyFormat = "pkcs1" PKCS8 keyFormat = "pkcs8" )
Variables ¶
This section is empty.
Functions ¶
func GenerateKeyPair ¶
GenerateKeyPair Generate rsa key pair with bits and format(PKCS1 or PKCS8) return private key and public key.
func Sign ¶
Sign rsa sign
Example ¶
priKey, pubKey, err := GenerateKeyPair(2048, PKCS8) if err != nil { log.Fatal(err) } src := []byte("trumanwong") sign, err := Sign(src, priKey, crypto.SHA256) if err != nil { log.Fatal(err) } err = Verify(src, sign, pubKey, crypto.SHA256) fmt.Println(err)
Output: <nil>
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.