rsae

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 17 Imported by: 16

README

rsae

rsa encrypt,decrypt,sign,verify wiht go

Base64Encode

package main

import (
	"fmt"

	"github.com/tiantour/rsae"
)

func main() {
	args := "input data"
	result := rsae.NewBase64().Encode([]byte(args))
	fmt.Println(result)
}

Base64Decode

package main

import (
	"fmt"

	"github.com/tiantour/rsae"
)

func main() {
	args := "input data"
	result, err := rsae.NewBase64().Decode(args)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(string(result))
}

MD532

package main

import (
	"fmt"

	"github.com/tiantour/rsae"
)

func main() {
	args := "input data"
	result := rsae.NewMD5().Encode(args)
	fmt.Println(result)
}

SHA1

package main

import (
	"fmt"

	"github.com/tiantour/rsae"
)

func main() {
	args := "input data"
	result := rsae.NewSHA().SHA1(args)
	fmt.Println(result)
}

SHA256

package main

import (
	"fmt"

	"github.com/tiantour/rsae"
)

func main() {
	args := "input data"
	result := rsae.NewSHA().SHA256(args)
	fmt.Println(result)
}

HmacSha1

package main

import (
	"fmt"

	"github.com/tiantour/rsae"
)

func main() {
	publicKey := "public key"
	privateKey := "private key"
	result := rsae.NewSHA().HmacSha1(publicKey, privateKey)
	fmt.Println(result)
}

Pbkdf2Sha256

package main

import (
	"fmt"

	"github.com/tiantour/rsae"
)

func main() {
	data := "input date"
	salt := "input salt"
	iterations := 12000
	result := rsae.NewSHA().Pbkdf2Sha256(data, salt, iterations)
	fmt.Println(result)
}

Encrypt

package main

import (
	"fmt"

	"github.com/tiantour/imago"
	"github.com/tiantour/rsae"
)

func main() {
	origdata := "data"
	publicPath := "public key path"
	publicKey, err := imago.NewFile().Read(publicPath)
	if err != nil {
		fmt.Println("key error")
	}
	result, err := rsae.NewRSA().Encrypt(origdata, publicKey)
	if err != nil {
		fmt.Println("encrypt error")
	}
	fmt.Println(result)
}

Decrypt

package main

import (
	"fmt"

	"github.com/tiantour/imago"
	"github.com/tiantour/rsae"
)

func main() {
	origdata := "data"
	privatePath := "public key path"
	privateKey, err := imago.NewFile().Read(privatePath)
	if err != nil {
		fmt.Println("key error")
	}
	result, err := rsae.NewRSA().Decrypt(origdata, privateKey)
	if err != nil {
		fmt.Println("Decrypt error")
	}
	fmt.Println(result)
}

Sign

package main

import (
	"fmt"

	"github.com/tiantour/imago"
	"github.com/tiantour/rsae"
)

func main() {
	origdata := "data"
	privatePath := "public key path"
	privateKey, err := imago.NewFile().Read(privatePath)
	if err != nil {
		fmt.Println("key error")
	}
	result, err := rsae.NewRSA().Sign(origdata, privateKey)
	if err != nil {
		fmt.Println("Decrypt error")
	}
	fmt.Println(result)
}

Verify

package main

import (
	"fmt"

	"github.com/tiantour/imago"
	"github.com/tiantour/rsae"
)

func main() {
	origdata := "data"
	ciphertext := "result"
	publicPath := "public key path"
	publicKey, err := imago.NewFile().Read(publicPath)
	if err != nil {
		fmt.Println("key error")
	}
	result, err := rsae.NewRSA().Verify(origdata, ciphertext, publicKey)
	if err != nil {
		fmt.Println("Decrypt error")
	}
	fmt.Println(result)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewECBEncrypter added in v1.0.2

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.

Types

type AES

type AES struct{}

AES aes

func NewAES

func NewAES() *AES

NewAES new aes

func (*AES) Decrypt

func (a *AES) Decrypt(ciphertext, key, iv []byte) ([]byte, error)

Decrypt aes decrypt

func (*AES) ECBDecrypt added in v1.0.2

func (a *AES) ECBDecrypt(ciphertext, key []byte) ([]byte, error)

ECBDecrypt aes decrypt ecb

func (*AES) ECBEncrypt added in v1.0.2

func (a *AES) ECBEncrypt(plantText, key []byte) ([]byte, error)

ECBEncrypt aes encrypt ecb

func (*AES) Encrypt

func (a *AES) Encrypt(plantText, key, iv []byte) ([]byte, error)

Encrypt aes encrypt

func (*AES) GCMDecrypt added in v1.0.5

func (a *AES) GCMDecrypt(key []byte, nonce []byte, cipherTextBase64, additionalData string) (string, error)

func (*AES) GCMEncrypt added in v1.0.5

func (a *AES) GCMEncrypt(key []byte, nonce []byte, plainText, additionalData string) (string, error)

type Base64

type Base64 struct{}

Base64 base64

func NewBase64

func NewBase64() *Base64

NewBase64 new base64

func (*Base64) Decode

func (b *Base64) Decode(data string) ([]byte, error)

Decode base64 descode

func (*Base64) Encode

func (b *Base64) Encode(data []byte) string

Encode base64 encode

type MD5

type MD5 struct{}

MD5 md5

func NewMD5

func NewMD5() *MD5

NewMD5 new md5

func (*MD5) Encode

func (m *MD5) Encode(data string) string

Encode md5 32

type PKCS7

type PKCS7 struct{}

PKCS7 pkcs7

func NewPKCS7

func NewPKCS7() *PKCS7

NewPKCS7 new pkcs7

func (*PKCS7) Padding

func (p *PKCS7) Padding(ciphertext []byte, blockSize int) []byte

Padding pkcs7 padding

func (*PKCS7) UnPadding

func (p *PKCS7) UnPadding(plantText []byte, blockSize int) []byte

UnPadding pkcs7 unpadding

type RSA

type RSA struct{}

RSA rsa

func NewRSA

func NewRSA() *RSA

NewRSA new rsa

func (*RSA) Decrypt

func (r *RSA) Decrypt(ciphertext string, privateKey []byte) (string, error)

Decrypt rsa decarypt

func (*RSA) Encrypt

func (r *RSA) Encrypt(origdata string, publicKey []byte) (string, error)

Encrypt rsa entrypt

func (*RSA) Sign

func (r *RSA) Sign(origdata string, privateKey []byte) (string, error)

Sign rsa sign

func (*RSA) SignWithSha256 added in v1.0.4

func (r *RSA) SignWithSha256(origdata string, privateKey []byte) (string, error)

SignWithSha256 sign with sha256

func (*RSA) Verify

func (r *RSA) Verify(origdata, ciphertext string, publicKey []byte) (bool, error)

Verify rsa verify

func (*RSA) VerifyWithSha256 added in v1.0.6

func (r *RSA) VerifyWithSha256(origdata, ciphertext string, publicKey []byte) (bool, error)

VerifyWithSha256 verify with sha256

type SHA

type SHA struct{}

SHA sha

func NewSHA

func NewSHA() *SHA

NewSHA new sha

func (*SHA) HmacSha1

func (s *SHA) HmacSha1(publicKey, privateKey string) []byte

HmacSha1 hmac sha1

func (*SHA) Pbkdf2Sha256

func (s *SHA) Pbkdf2Sha256(data, salt string, iterations int) string

Pbkdf2Sha256 pbkdf2 sha256

func (*SHA) SHA1

func (s *SHA) SHA1(data string) []byte

SHA1 sha1

func (*SHA) SHA256

func (s *SHA) SHA256(data string) []byte

SHA256 sha256

Jump to

Keyboard shortcuts

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