rsa

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RsaDecode

func RsaDecode(data string, private []byte) ([]byte, error)

解密

func RsaEncrypt

func RsaEncrypt(orgidata, publickey []byte) (string, error)

func Sign

func Sign(plant []byte, private []byte) (string, error)

签名

func Sign256

func Sign256(plant []byte, private []byte) (string, error)

签名

func Verify

func Verify(sign string, plant []byte, public []byte) (bool, error)

验证签名

Types

type Cipher

type Cipher interface {
	Encrypt(plainText []byte) ([]byte, error)
	Decrypt(cipherText []byte) ([]byte, error)
	Sign(src []byte, hash crypto.Hash) ([]byte, error)
	Verify(src []byte, sign []byte, hash crypto.Hash) error
}

func NewCipher

func NewCipher(key Key, padding Padding, cipherMode CipherMode, signMode SignMode) Cipher

func NewRSA

func NewRSA(key Key) (Cipher, error)

func NewRSAWith

func NewRSAWith(key Key, padding Padding, cipherMode CipherMode, signMode SignMode) (Cipher, error)

type CipherMode

type CipherMode interface {
	Encrypt(plainText []byte, puk *rsa.PublicKey) ([]byte, error)
	Decrypt(cipherText []byte, prk *rsa.PrivateKey) ([]byte, error)
}

func NewPKCS1v15Cipher

func NewPKCS1v15Cipher() CipherMode

type Key

type Key interface {
	PublicKey() *rsa.PublicKey
	PrivateKey() *rsa.PrivateKey
	Modulus() int
}

func LoadKeyFromPEMFile

func LoadKeyFromPEMFile(publicKeyFilePath, privateKeyFilePath string, ParseKey func([]byte, []byte) (Key, error)) (Key, error)

func ParsePKCS1Key

func ParsePKCS1Key(publicKey, privateKey []byte) (Key, error)

func ParsePKCS1KeyPrivate

func ParsePKCS1KeyPrivate(privateKey []byte) (Key, error)

func ParsePKCS1KeyPublic

func ParsePKCS1KeyPublic(publicKey []byte) (Key, error)

func ParsePKCS8Key

func ParsePKCS8Key(publicKey, privateKey []byte) (Key, error)

type Padding

type Padding interface {
	Padding(src []byte) [][]byte
}

func NewNoPadding

func NewNoPadding(modulus int) Padding

func NewOAEPPadding

func NewOAEPPadding(modulus int) Padding

func NewPKCS1Padding

func NewPKCS1Padding(modulus int) Padding

type SignMode

type SignMode interface {
	Sign(src []byte, hash crypto.Hash, prk *rsa.PrivateKey) ([]byte, error)
	Verify(src []byte, sign []byte, hash crypto.Hash, puk *rsa.PublicKey) error
}

func NewPKCS1v15Sign

func NewPKCS1v15Sign() SignMode

Jump to

Keyboard shortcuts

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