openssl

package
v0.3.30 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const PKCS5_PADDING = "PKCS5"
View Source
const PKCS7_PADDING = "PKCS7"
View Source
const ZEROS_PADDING = "ZEROS"

Variables

View Source
var (
	ErrBlockNil = errors.New("block is nil")
)
View Source
var ErrInvalidFormat = errors.New("key is invalid format")
View Source
var ErrUnPadding = errors.New("UnPadding error")

Functions

func AesCBCDecrypt

func AesCBCDecrypt(src, key, iv []byte, padding string) ([]byte, error)

AesCBCDecrypt 使用AES算法的CBC模式进行密码解密。 参数src为待解密的数据,key为解密密钥,iv为初始向量,padding为填充方式。 返回解密后的数据和可能的错误。

func AesCBCEncrypt

func AesCBCEncrypt(src, key, iv []byte, padding string) ([]byte, error)

AesCBCEncrypt 使用AES算法进行CBC模式加密。 参数src是要加密的数据。 参数key是加密密钥。 参数iv是初始化向量。 参数padding是填充方式。 返回加密后的数据和可能的错误。

func AesECBDecrypt

func AesECBDecrypt(src, key []byte, padding string) ([]byte, error)

AesECBDecrypt 使用AES算法的ECB模式进行解密 参数:

  • src: 待解密的数据
  • key: 解密密钥
  • padding: 填充方式

返回值:

  • []byte: 解密后的数据
  • error: 解密过程中遇到的错误

func AesECBEncrypt

func AesECBEncrypt(src, key []byte, padding string) ([]byte, error)

AesECBEncrypt 使用AES算法的ECB模式进行加密。 参数src为待加密的数据,key为加密密钥,padding为填充方式。 返回加密后的数据和可能的错误。

func AesNewCipher

func AesNewCipher(key []byte) (cipher.Block, error)

AesNewCipher 使用AES算法创建一个新的加密器。 参数key为加密使用的密钥。 返回值为一个实现cipher.Block接口的加密器和一个错误。

func CBCDecrypt

func CBCDecrypt(block cipher.Block, src, iv []byte, padding string) ([]byte, error)

CBCDecrypt 使用CBC模式解密算法对密文进行解密操作。 参数:

  • block:使用的加密块。
  • src:待解密的密文。
  • iv:初始向量,长度必须等于块大小。
  • padding:填充方式。

返回值:

  • []byte:解密后的明文。
  • error:解密过程中可能发生的错误。

func CBCEncrypt

func CBCEncrypt(block cipher.Block, src, iv []byte, padding string) ([]byte, error)

CBCEncrypt 使用CBC模式加密算法对给定的数据进行加密 参数:

  • block:使用的加密块
  • src:要加密的数据
  • iv:初始化向量(IV)
  • padding:填充方式

返回值:

  • []byte:加密后的数据
  • error:如果加密过程中发生错误,则返回错误信息

func Des3CBCDecrypt

func Des3CBCDecrypt(src, key, iv []byte, padding string) ([]byte, error)

Des3CBCDecrypt 使用Triple DES算法和CBC模式进行密码解密。 参数src为待解密的数据,key为解密密钥,iv为初始向量,padding为填充方式。 返回解密后的数据和错误信息。

func Des3CBCEncrypt

func Des3CBCEncrypt(src, key, iv []byte, padding string) ([]byte, error)

Des3CBCEncrypt 使用Triple DES算法和CBC模式对给定的源数据进行加密。 参数src是要加密的数据。 参数key是加密密钥。 参数iv是初始化向量。 参数padding是填充模式。 返回加密后的数据和可能的错误。

func Des3ECBDecrypt

func Des3ECBDecrypt(src, key []byte, padding string) ([]byte, error)

Des3ECBDecrypt 使用TripleDESCipher算法进行密码解密

func Des3ECBEncrypt

func Des3ECBEncrypt(src, key []byte, padding string) ([]byte, error)

Des3ECBEncrypt 使用Triple DES算法进行ECB模式加密。 参数src是要加密的数据。 参数key是加密密钥。 参数padding是填充方式,目前仅支持PKCS5Padding。 返回加密后的数据和可能的错误。

func DesCBCDecrypt

func DesCBCDecrypt(src, key, iv []byte, padding string) ([]byte, error)

DesCBCDecrypt 使用DES算法的CBC模式进行密码解密 参数:

  • src: 待解密的数据
  • key: 解密密钥
  • iv: 初始化向量
  • padding: 填充方式

返回值:

  • []byte: 解密后的数据
  • error: 如果解密失败,返回错误信息

func DesCBCEncrypt

func DesCBCEncrypt(src, key, iv []byte, padding string) ([]byte, error)

DesCBCEncrypt 使用DES算法进行CBC模式加密。 参数:

  • src:待加密的数据
  • key:加密密钥
  • iv:初始化向量
  • padding:填充方式

返回值:

  • []byte:加密后的数据
  • error:如果加密过程中发生错误,返回错误信息

func DesECBDecrypt

func DesECBDecrypt(src, key []byte, padding string) ([]byte, error)

DesECBDecrypt 使用DES算法的ECB模式进行解密。 参数src为待解密的数据,key为解密密钥,padding为填充方式。 返回解密后的数据和错误信息(如果有)。

func DesECBEncrypt

func DesECBEncrypt(src, key []byte, padding string) ([]byte, error)

DesECBEncrypt 使用DES算法的ECB模式进行加密。 参数src是要加密的数据。 参数key是加密密钥。 参数padding是填充方式,可选值为"PKCS5Padding"或"PKCS7Padding"。 返回加密后的数据和可能的错误。

func DesNewCipher

func DesNewCipher(key []byte) (cipher.Block, error)

DesNewCipher 用于创建一个DES加密算法的密码块。 参数 key 是加密算法的密钥,长度必须为8字节。 如果 key 的长度小于8字节,则在 key 的末尾补0直到长度为8字节。 如果 key 的长度大于8字节,则截取前8字节作为密钥。 返回一个 cipher.Block 对象和一个 error 对象。 如果密钥长度不正确,将返回一个错误。

func ECBDecrypt

func ECBDecrypt(block cipher.Block, src []byte, padding string) ([]byte, error)

ECBDecrypt 使用ECB模式解密算法对给定的数据进行解密操作。 参数:

  • block:加密算法的块密码。
  • src:待解密的数据。
  • padding:填充方式。

返回值:

  • []byte:解密后的数据。
  • error:解密操作过程中遇到的错误。

func ECBEncrypt

func ECBEncrypt(block cipher.Block, src []byte, padding string) ([]byte, error)

ECBEncrypt 使用ECB模式加密算法对给定的数据进行加密。 参数:

  • block:加密算法的块
  • src:要加密的数据
  • padding:填充方式

返回值:

  • []byte:加密后的数据
  • error:如果加密算法的块为nil,则返回ErrBlockNil错误

func HmacSha1

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

HmacSha1 Calculate the sha1 hash of a string using the HMAC method

func HmacSha1ToString

func HmacSha1ToString(key string, data string) string

HmacSha1ToString Calculate the sha1 hash of a string using the HMAC method, outputs lowercase hexits

func HmacSha256

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

HmacSha256 Calculate the sha256 hash of a string using the HMAC method

func HmacSha256ToString

func HmacSha256ToString(key string, data string) string

HmacSha256ToString Calculate the sha256 hash of a string using the HMAC method, outputs lowercase hexits

func KeyGenerator

func KeyGenerator(src []byte, blockSize int) []byte

func Md5

func Md5(str string) []byte

Md5 Calculate the md5 hash of a string

func Md5ToString

func Md5ToString(str string) string

Md5ToString Calculate the md5 hash of a string, return hex string

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter 返回一个ECB解密器的实例。 参数b为一个cipher.Block,用于初始化解密器。 返回一个cipher.BlockMode类型的指针。

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter 返回一个使用ECB模式的加密器。 参数b为一个cipher.Block类型的参数,用于初始化加密器。

func PKCS5Padding

func PKCS5Padding(src []byte, blockSize int) []byte

func PKCS5Unpadding

func PKCS5Unpadding(src []byte) ([]byte, error)

func PKCS7Padding

func PKCS7Padding(src []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(src []byte) ([]byte, error)

func Padding

func Padding(padding string, src []byte, blockSize int) []byte

func RSADecrypt

func RSADecrypt(src, priKey []byte) ([]byte, error)

RSADecrypt RSA decrypt

func RSAEncrypt

func RSAEncrypt(src, pubKey []byte) ([]byte, error)

RSAEncrypt RSA encrypt

func RSAGenerateKey

func RSAGenerateKey(bits int, out io.Writer) error

RSAGenerateKey generate RSA private key

func RSAGeneratePublicKey

func RSAGeneratePublicKey(priKey []byte, out io.Writer) error

RSAGeneratePublicKey generate RSA public key

func RSASign

func RSASign(src []byte, priKey []byte, hash crypto.Hash) ([]byte, error)

RSASign RSA sign

func RSAVerify

func RSAVerify(src, sign, pubKey []byte, hash crypto.Hash) error

RSAVerify RSA verify

func SHA1

func SHA1(data []byte) []byte

func Sha1

func Sha1(str string) []byte

Sha1 Calculate the sha1 hash of a string

func Sha256

func Sha256(str string) []byte

Sha256 Calculate the sha256 hash of a string

func UnPadding

func UnPadding(padding string, src []byte) ([]byte, error)

func ZerosPadding

func ZerosPadding(src []byte, blockSize int) []byte

func ZerosUnPadding

func ZerosUnPadding(src []byte) ([]byte, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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