rsam

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2022 License: MIT Imports: 11 Imported by: 2

README

rsa-modified (rsam)

Supports additional functionalites and important stuff must be done in some corner cases and some specific applications

Modified package for RSA encryption and decryption to allow large message encryption and decryption and to allow encryption through private key and decryption through public key and signature through public key and private key and vice versa. i.e. Additional functionalities to the existing crypto package

Installation
go get "github.com/gossl/rsam"
Usage
import  (
  "bytes"
  "fmt"
  
  "github.com/gossl/rsam"
)

func main(){
  priv, pub, err := rsam.GenerateKeyPair(2048)
  if err != nil {
    panic(err)
  }
  msg := []byte("hello world")
  ciphertext, err := rsam.EncryptWithPrivateKey(msg, priv, sha256.New())
  if err != nil {
    panic(err)
  }
  plaintext, err := rsam.DecryptWithPublicKey(encrypted, pub, sha256.New())
  if err != nil {
    panic(err)
  }
  if !bytes.Equal(msg, plaintext) {
   panic(nil)
 }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func B64DecodeKeyFile

func B64DecodeKeyFile(path string) (string, error)

Returns decoding of base64 encoded key from file

func B64DecodeKeyString

func B64DecodeKeyString(key string) (string, error)

Returns base64 encoded public key from string

func B64EncodeKeyFile

func B64EncodeKeyFile(path string) (string, error)

Returns base64 encoded key from file

func B64EncodeKeyString

func B64EncodeKeyString(key string) string

Returns base64 encoded public key from string

func BytesToPrivateKey

func BytesToPrivateKey(priv []byte) (*rsa.PrivateKey, error)

Converts bytes to private key

func BytesToPublicKey

func BytesToPublicKey(pub []byte) (*rsa.PublicKey, error)

Converts bytes to public key

func DecryptWithPrivateKey

func DecryptWithPrivateKey(ciphertext []byte, priv *rsa.PrivateKey, hash hash.Hash) ([]byte, error)

Decrypts data with private key

func DecryptWithPublicKey

func DecryptWithPublicKey(ciphertext []byte, pub *rsa.PublicKey, hash hash.Hash) ([]byte, error)

Decrypts data with private key

func EncryptWithPrivateKey

func EncryptWithPrivateKey(msg []byte, priv *rsa.PrivateKey, hash hash.Hash) ([]byte, error)

Encrypts data with public key

func EncryptWithPublicKey

func EncryptWithPublicKey(msg []byte, pub *rsa.PublicKey, hash hash.Hash) ([]byte, error)

Encrypts data with public key

func GeneratePairKeys

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

Generates a new key pair (private and public)

func PrivateKeyToBytes

func PrivateKeyToBytes(priv *rsa.PrivateKey) []byte

Converts private key to bytes

func PublicKeyToBytes

func PublicKeyToBytes(pub *rsa.PublicKey) []byte

Converts public key to bytes

func SignWithPrivateKey

func SignWithPrivateKey(msg []byte, priv *rsa.PrivateKey, hashOpt ...crypto.Hash) ([]byte, error)

Decrypts data with private key

func SignWithPublicKey

func SignWithPublicKey(msg []byte, pub *rsa.PublicKey) ([]byte, error)

Encrypts data with public key

func VerifyWithPrivateKey

func VerifyWithPrivateKey(msg []byte, signature []byte, priv *rsa.PrivateKey) error

Decrypts data with private key

func VerifyWithPublicKey

func VerifyWithPublicKey(msg []byte, signature []byte, pub *rsa.PublicKey, hashOpt ...crypto.Hash) error

Decrypts data with private key

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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