crypto

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	VisualCharAll       = 0
	VisualCharNumber    = 1
	VisualCharCapital   = 2
	VisualCharLowercase = 3
	VisualCharSpecial   = 4
)
View Source
var CapitalCharList = make([]uint64, 26)
View Source
var CapitalCharMap = make(map[byte]uint64)
View Source
var LowercaseCharList = make([]uint64, 26)
View Source
var LowercaseCharMap = make(map[byte]uint64)
View Source
var NumberCharList = make([]uint64, 10)
View Source
var NumberCharMap = make(map[byte]uint64)
View Source
var SpecialCharList = make([]uint64, 128)
View Source
var SpecialCharMap = make(map[byte]uint64)
View Source
var VisualCharList = make([]uint64, 256)

Functions

func Base64Decode

func Base64Decode(data string) ([]byte, error)

Base64Decode base64 decode.

func Base64DecodeURL

func Base64DecodeURL(data string) ([]byte, error)

Base64DecodeURL base64 url decode.

func Base64Encode

func Base64Encode(data []byte) string

Base64Encode base64 encode.

func Base64EncodeURL

func Base64EncodeURL(data []byte) string

Base64EncodeURL base64 url encode.

func CRC32Cp

func CRC32Cp(data []byte) uint32

CRC32Cp hash.

func CRC32IEEE

func CRC32IEEE(data []byte) uint32

CRC32IEEE hash.

func CRC32Kp

func CRC32Kp(data []byte) uint32

CRC32Kp hash.

func CRC64ECMA

func CRC64ECMA(data []byte) uint64

CRC64ECMA hash.

func CRC64ISO

func CRC64ISO(data []byte) uint64

CRC64ISO hash.

func EncodePrivateKeyBufferRSA

func EncodePrivateKeyBufferRSA(priKey *rsa.PrivateKey) []byte

EncodePrivateKeyBufferRSA format RSA private key as bytes.

func EncodePrivateKeyFileRSA

func EncodePrivateKeyFileRSA(priKey *rsa.PrivateKey, fileName string) error

EncodePrivateKeyFileRSA format RSA private key as file.

func EncodePublicKeyBufferRSA

func EncodePublicKeyBufferRSA(pubKey *rsa.PublicKey) ([]byte, error)

EncodePublicKeyBufferRSA format RSA public key as bytes.

func EncodePublicKeyFileRSA

func EncodePublicKeyFileRSA(pubKey *rsa.PublicKey, fileName string) error

EncodePublicKeyFileRSA format RSA public key as file.

func GenerateKeyRSA

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

GenerateKeyRSA generate RSA public and private key pair.

func GetCertBytes

func GetCertBytes(cert *pem.Block, key *pem.Block) ([]byte, []byte)

GetCertBytes Save the certificate as bytes.

func GetHmacSha256Hex

func GetHmacSha256Hex(key string, data []byte) string

func IsAccountEn

func IsAccountEn(str string) (bool, error)

IsAccountEn is english account, windows not support file or dir name include: \/:*?"<>|

func IsAccountZh

func IsAccountZh(str string) (bool, error)

IsAccountZh is chinese account.

func IsEmail

func IsEmail(str string) (bool, error)

IsEmail is email address.

func IsIPPort

func IsIPPort(str string) (bool, error)

IsIPPort is net port, 1-65535.

func IsIPv4

func IsIPv4(str string) (bool, error)

IsIPv4 is IPv4 address, 0.0.0.0 - 255.255.255.255.

func IsPhone

func IsPhone(str string) (bool, error)

IsPhone is phone number.

func IssueCertImpl

func IssueCertImpl(rootCa *x509.Certificate, rootKey *rsa.PrivateKey) (*pem.Block, *pem.Block, error)

IssueCertImpl Issue sub-certificates based on the root certificate

func LoadPublicKeyRSA

func LoadPublicKeyRSA(pubKey []byte) (*rsa.PublicKey, error)

LoadPublicKeyRSA Parse the public key from the public key byte stream (the key must be formatted).

func LoadRSAPrivateKeyPKCS1

func LoadRSAPrivateKeyPKCS1(priKey []byte) (*rsa.PrivateKey, error)

LoadRSAPrivateKeyPKCS1 Parse the private key from the key byte stream (the key must be formatted), using PKCS1.

func LoadRSAPrivateKeyPKCS8

func LoadRSAPrivateKeyPKCS8(priKey []byte) (*rsa.PrivateKey, error)

LoadRSAPrivateKeyPKCS8 Parse the private key from the key byte stream (the key must be formatted), using PKCS8.

func LoadRootCa

func LoadRootCa(caFile string, keyFile string) (*x509.Certificate, *rsa.PrivateKey, error)

LoadRootCa load ca.

func MD5

func MD5(data []byte) ([]byte, error)

MD5 hash.

func Number

func Number(maxNum uint64) (uint64, error)

Number get random number,0<= value < maxNum.

func Password

func Password(length uint64) (string, error)

Password generate random password of specified length

func RsaDecryptRSA

func RsaDecryptRSA(cipherText []byte, myPriKey *rsa.PrivateKey) ([]byte, error)

RsaDecryptRSA RSA decryption, decrypt with your own private key

func RsaEncryptRSA

func RsaEncryptRSA(plainText []byte, peerPubKey *rsa.PublicKey) ([]byte, error)

RsaEncryptRSA RSA encryption, using the peer's public key encryption.

func SaveCert2File

func SaveCert2File(cert *pem.Block, key *pem.Block, certFile string, keyFile string) error

SaveCert2File Save the certificate as file.

func Sha1

func Sha1(data []byte) ([]byte, error)

Sha1 hash.

func Sha256

func Sha256(data []byte) ([]byte, error)

Sha256 hash.

func Sha512

func Sha512(data []byte) ([]byte, error)

Sha512 hash.

func SignWithSha256RSA

func SignWithSha256RSA(data []byte, myPriKey []byte) ([]byte, error)

SignWithSha256RSA Digitally sign the hash value of the data with your own private key.

func String

func String(length int) (string, error)

String get random string that length is defined

func VerySignWithSha256RSA

func VerySignWithSha256RSA(originalDataHash []byte, signedDataHash []byte, peerPubKey []byte) error

VerySignWithSha256RSA Verifies the hash of the signature using the counterparty's public key.

Types

type Curve22519Ecdh

type Curve22519Ecdh struct {
	PublicKey  string
	PrivateKey string
	// contains filtered or unexported fields
}

Curve22519Ecdh curve22519 ECDH.

func NewCurve22519Ecdh

func NewCurve22519Ecdh() *Curve22519Ecdh

NewCurve22519Ecdh create curve22519 ecdh.

func (*Curve22519Ecdh) GenerateKeyPair

func (c *Curve22519Ecdh) GenerateKeyPair() error

GenerateKeyPair Generate a public and private key pair.

func (*Curve22519Ecdh) GetPublicKey

func (c *Curve22519Ecdh) GetPublicKey() string

GetPublicKey get public key.

func (*Curve22519Ecdh) GetSharedKey

func (c *Curve22519Ecdh) GetSharedKey(peerPubKey string) (string, error)

GetSharedKey get shared key.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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