rsa

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 7 Imported by: 0

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

Examples

Constants

View Source
const (
	PKCS1 keyFormat = "pkcs1"
	PKCS8 keyFormat = "pkcs8"
)

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(src, privateKey []byte) ([]byte, error)

Decrypt RSA Decrypt

func Encrypt

func Encrypt(src, publicKey []byte) (dst []byte, err error)

Encrypt RSA Encrypt

func GenerateKeyPair

func GenerateKeyPair(bits int, format keyFormat) (privateKey, publicKey []byte, err error)

GenerateKeyPair Generate rsa key pair with bits and format(PKCS1 or PKCS8) return private key and public key.

func Sign

func Sign(src []byte, privateKey []byte, hash crypto.Hash) ([]byte, error)

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>

func Verify

func Verify(src, sign, publicKey []byte, hash crypto.Hash) error

Verify rsa verify

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL