crypto

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: GPL-2.0 Imports: 22 Imported by: 0

README

Standard Modules


Documentation

Index

Constants

View Source
const (
	RSA2048Bits uint32 = 1 << 11
)

Variables

View Source
var (
	CertOptDefault = CertOption{
		Issuer: pkix.Name{
			Country:            []string{"VN"},
			Organization:       []string{},
			OrganizationalUnit: []string{},
			CommonName:         "",
		},
		SubjectNameObject: pkix.Name{
			Country:            []string{"VN"},
			Organization:       []string{"ioVN Co., Ltd"},
			OrganizationalUnit: []string{},
			Locality:           []string{},
			Province:           []string{"Some-State"},
			CommonName:         "",
		},
		MakeExpires: func() time.Time {
			return time.Now().AddDate(1, 0, 0)
		},
	}
)

Functions

func AESDecryptCBC

func AESDecryptCBC(keySt []byte, ciphertext []byte) (decrypted []byte, err error)

AESDecryptCBC decrypt aes in CBC mode and remove pkcs7 padding.

func AESEncryptCBC

func AESEncryptCBC(keyByte []byte, plaintext []byte) ([]byte, error)

AESEncryptCBC padding with pkcs7 before encrypt with CBC mode.

func AESGenerate256Key

func AESGenerate256Key() (key []byte, err error)

AESGenerate256Key : generate an 256 bits AES key.

func RSADecryptOAEP

func RSADecryptOAEP(ciphertext, privateKey []byte) (output []byte, err error)

RSADecryptOAEP decrypts ciphertext using RSA-OAEP, privateKey in PKCS#8 encoded form.

func RSAEncryptOAEP

func RSAEncryptOAEP(publicKey, data []byte) (output []byte, err error)

RSAEncryptOAEP : encrypts the given message with RSA-OAEP, publicKey in DER-encoded PKIX format.

func RSASignMessage

func RSASignMessage(message []byte, signKey []byte) (signature string, err error)

RSASignMessage sign message, return base64 signature

func RSAVerifySignature

func RSAVerifySignature(sig string, message []byte, verifyKey []byte) error

RSAVerifySignature verify signature, return nil is signature valid, sig is signature base64 sig base64 encoding, message raw message

Types

type CertOption

type CertOption struct {
	Issuer, SubjectNameObject pkix.Name
	MakeExpires               func() time.Time
	EmailAddresses            []string
}

type HASH

type HASH []byte

func SHA256

func SHA256(data []byte) HASH

func (HASH) Hex

func (value HASH) Hex() string

type Keypair

type Keypair struct {
	PrivateKey []byte
	PublicKey  []byte
}

Keypair :

type OpenSSL

type OpenSSL struct {
	// contains filtered or unexported fields
}

func (*OpenSSL) Certificate

func (ssl *OpenSSL) Certificate() *x509.Certificate

Certificate : Get *x509.Certificate object.

Note: Must call after GenRSA() or ImportP12() function

func (*OpenSSL) ExportP12

func (ssl *OpenSSL) ExportP12(pwd string, output string) error

ExportP12 : save keyPair to pkcs12 type.

Note: Must call after GenRSA() or ImportP12() function

func (*OpenSSL) GenRSA

func (ssl *OpenSSL) GenRSA(bits uint32, args ...string) (err error)

GenRSA : This command generates an RSA private key.

$ openssl genrsa -out private.pem 2048

func (*OpenSSL) ImportP12

func (ssl *OpenSSL) ImportP12(data []byte, pwd string) error

ImportP12 with private.p12

$ openssl pkcs12 -in private.p12 -clcerts -nokeys -out PublicKey.cer

$ openssl pkcs12 -in private.p12 -nodes -nocerts | openssl rsa -out PrivateKey.key

func (*OpenSSL) MakeCertificate

func (ssl *OpenSSL) MakeCertificate(opt *CertOption) error

MakeCertificate : Make *x509.Certificate value for OpenSSL object.

Note: Must call after GenRSA() function

func (*OpenSSL) PrivateKey

func (ssl *OpenSSL) PrivateKey() *rsa.PrivateKey

PrivateKey : Get *rsa.PrivateKey object.

Note: Must call after GenRSA() or ImportP12() function

Directories

Path Synopsis
rc2

Jump to

Keyboard shortcuts

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