rsautil

package module
v0.0.0-...-178e088 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: MIT Imports: 8 Imported by: 0

README

rsautil

some frequenetly used rsa crypto utils, e.g.

  • GenerateKey
  • EncodePrivateKey
  • EncodePublicKey
  • Encrypt
  • Decrypt
  • SignWithSha256Base64
  • VerySignWithSha256Base64

An example

func TestSignAndVerify(t *testing.T)  {
	sk, pk, _ := GenerateKey(1024)
	skBytes := EncodePrivateKey(sk)
	pkBytes, _ := EncodePublicKey(pk)
	fmt.Println(string(skBytes))
	fmt.Println(string(pkBytes))

	sig, err := SignWithSha256Base64("test", skBytes)
	if err != nil{
		fmt.Printf("%+v", err)
	}
	fmt.Println(sig)

	success, err := VerySignWithSha256Base64("test", sig, pkBytes)
	if success {
		fmt.Println("pass")
	} else {
		fmt.Printf("%+v", err)
	}
}

Usage

内部API的安全防护怎么搞?密码学中有答案

Code:ApiSecurityDemo

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

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

func EncodePrivateKey

func EncodePrivateKey(private *rsa.PrivateKey) []byte

func EncodePublicKey

func EncodePublicKey(public *rsa.PublicKey) ([]byte, error)

func Encrypt

func Encrypt(publicKey []byte, origData []byte) ([]byte, error)

func GenerateKey

func GenerateKey(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)

func SignWithSha256Base64

func SignWithSha256Base64(data string, prvKeyBytes []byte) (string, error)

func VerySignWithSha256Base64

func VerySignWithSha256Base64(originalData, signData string, pubKeyBytes []byte) (bool, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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