Documentation ¶
Overview ¶
* This file copy from https://github.com/qyxing/ostar/blob/master/codec/rsa_ext.go * It's license same with upstream.
Index ¶
- Constants
- Variables
- func PKCS5Padding(buf []byte, blockSize int) []byte
- func PKCS7Padding(buf []byte, blockSize int) (padded []byte)
- func UnPKCS5Padding(buf []byte) []byte
- func UnZeroPadding(buf []byte) []byte
- func ZeroPadding(buf []byte, blockSize int) []byte
- type AES
- func (this *AES) AESInit(key, iv []byte) error
- func (this *AES) CBCDecrypt(inputBuf []byte, p int) []byte
- func (this *AES) CBCDecryptFromBase64String(inputStr string, p int) ([]byte, error)
- func (this *AES) CBCDecryptFromHexString(inputStr string, p int) ([]byte, error)
- func (this *AES) CBCEncrypt(inputBuf []byte, p int) []byte
- func (this *AES) CBCEncryptToBase64String(inputBuf []byte, p int) string
- func (this *AES) CBCEncryptToHexString(inputBuf []byte, p int) string
- func (this *AES) Decrypt(inputBuf []byte, p int) []byte
- func (this *AES) DecryptFromBase64String(inputStr string, p int) ([]byte, error)
- func (this *AES) DecryptFromHexString(inputStr string, p int) ([]byte, error)
- func (this *AES) Encrypt(inputBuf []byte, p int) []byte
- func (this *AES) EncryptToBase64String(inputBuf []byte, p int) string
- func (this *AES) EncryptToHexString(inputBuf []byte, p int) string
- func (this *AES) GetBlock() cipher.Block
- func (this *AES) GetBlockSize() int
- type DES
- func (this *DES) CBCDecrypt(inputBuf []byte, p int) []byte
- func (this *DES) CBCDecryptFromBase64String(inputStr string, p int) ([]byte, error)
- func (this *DES) CBCDecryptFromHexString(inputStr string, p int) ([]byte, error)
- func (this *DES) CBCEncrypt(inputBuf []byte, p int) []byte
- func (this *DES) CBCEncryptToBase64String(inputBuf []byte, p int) string
- func (this *DES) CBCEncryptToHexString(inputBuf []byte, p int) string
- func (this *DES) DESInit(key, iv []byte) error
- func (this *DES) Decrypt(inputBuf []byte, p int) []byte
- func (this *DES) DecryptFromBase64String(inputStr string, p int) ([]byte, error)
- func (this *DES) DecryptFromHexString(inputStr string, p int) ([]byte, error)
- func (this *DES) Encrypt(inputBuf []byte, p int) []byte
- func (this *DES) EncryptToBase64String(inputBuf []byte, p int) string
- func (this *DES) EncryptToHexString(inputBuf []byte, p int) string
- func (this *DES) GetBlock() cipher.Block
- func (this *DES) GetBlockSize() int
- type HMac
- type RSA
- func (this *RSA) GenerateKeyWithBits(bits int) ([]byte, []byte, error)
- func (this *RSA) GeneratePrivateKey(bits int) ([]byte, error)
- func (this *RSA) GeneratePublicKey() ([]byte, error)
- func (this *RSA) ParsePKCS1PrivateKey() error
- func (this *RSA) ParsePKCS1PublicKey() error
- func (this *RSA) PrivateKeyDecrypt(cipher string) ([]byte, error)
- func (this *RSA) PublicKeyEncrypt(buf []byte) (string, error)
- func (this *RSA) Sign(src []byte, hash crypto.Hash) (string, error)
- type Sha
- func (this *Sha) Md5(buf []byte) []byte
- func (this *Sha) Md5ToBase64String(text string) string
- func (this *Sha) Md5ToHexString(text string) string
- func (this *Sha) Sha1(buf []byte) []byte
- func (this *Sha) Sha1ToBase64String(text string) string
- func (this *Sha) Sha1ToHexString(text string) string
- func (this *Sha) Sha256(buf []byte) []byte
- func (this *Sha) Sha256ToBase64String(text string) string
- func (this *Sha) Sha256ToHexString(text string) string
- func (this *Sha) Sha512(buf []byte) []byte
- func (this *Sha) Sha512ToBase64String(text string) string
- func (this *Sha) Sha512ToHexString(text string) string
- type TripleDES
- func (this *TripleDES) CBCDecrypt(inputBuf []byte, p int) []byte
- func (this *TripleDES) CBCDecryptFromBase64String(inputStr string, p int) ([]byte, error)
- func (this *TripleDES) CBCDecryptFromHexString(inputStr string, p int) ([]byte, error)
- func (this *TripleDES) CBCEncrypt(inputBuf []byte, p int) []byte
- func (this *TripleDES) CBCEncryptToBase64String(inputBuf []byte, p int) string
- func (this *TripleDES) CBCEncryptToHexString(inputBuf []byte, p int) string
- func (this *TripleDES) Decrypt(inputBuf []byte, p int) []byte
- func (this *TripleDES) DecryptFromBase64String(inputStr string, p int) ([]byte, error)
- func (this *TripleDES) DecryptFromHexString(inputStr string, p int) ([]byte, error)
- func (this *TripleDES) Encrypt(inputBuf []byte, p int) []byte
- func (this *TripleDES) EncryptToBase64String(inputBuf []byte, p int) string
- func (this *TripleDES) EncryptToHexString(inputBuf []byte, p int) string
- func (this *TripleDES) GetBlock() cipher.Block
- func (this *TripleDES) GetBlockSize() int
- func (this *TripleDES) TripleDESInit(key, iv []byte) error
Constants ¶
const ( PADDING_ZERO = 0 PADDING_PKCS5 = 1 )
Variables ¶
var ( ErrDataToLarge = errors.New("message too long for RSA public key size") ErrDataLen = errors.New("data length error") ErrDataBroken = errors.New("data broken, first byte is not zero") ErrKeyPairDismatch = errors.New("data is not encrypted by the private key") ErrDecryption = errors.New("decryption error") ErrPublicKey = errors.New("get public key error") ErrPrivateKey = errors.New("get private key error") )
Functions ¶
func PKCS5Padding ¶
PKCS5 is a subset of PKCS7. Handle the bytes creates and returns a new TripleDES. The key argument should be the TripleDES key, * either 8, 16, or 24 bytes to select TripleDES with 1 key, TripleDES with 2 key, * or TripleDES with 3 key. The length of iv must be the same as the Block's block size. * If an 8 bytes key, and it is the same as DES. * * @param text the TripleDES key * @param iv the iv key * * @return *TripleDES TripleDES instance * @return error Errors encountered
func PKCS7Padding ¶
func UnPKCS5Padding ¶
func UnZeroPadding ¶
func ZeroPadding ¶
Types ¶
type AES ¶
type AES struct {
// contains filtered or unexported fields
}
func NewAES ¶
creates and returns a new AES. The key argument should be the AES key, * either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256. * The length of iv must be the same as the Block's block size. * * @param key The AES key * @param iv The iv key * * @return *AES AES instance * @return error Errors encountered *
func (*AES) AESInit ¶
初始化 AES 实例,16, 24, 或 32 字节来选择 AES-128, AES-192, 或 AES-256 * * @param key AES 加解密密钥 * @param iv 16 字节 CBC 初始化向量 * * @return error 遇到的错误 *
func (*AES) CBCDecrypt ¶
CBC 解密 * * @param inputBuf 要解密的密文数据 * @param p 数据填充方式 * * @return []byte 解密后的数据 *
func (*AES) CBCDecryptFromBase64String ¶
CBC 解密 base64 格式的密文 * * @param inputBuf 要解密的 base64 编码密文字符 * @param p 数据填充方式 * * @return []byte 解密后的数据 * @return error 解密中出现的错误信息 *
func (*AES) CBCDecryptFromHexString ¶
CBC 解密 hex 格式的密文 * * @param inputBuf 要解密的Hex编码密文字符 * @param p 数据填充方式 * * @return []byte 解密后的数据 * @return error 解密中出现的错误信息 *
func (*AES) CBCEncrypt ¶
CBC 加密 * * @param inputBuf 要加密的明文数据 * @param p 数据填充方式 * * @return []byte 加密后的数据 *
func (*AES) CBCEncryptToBase64String ¶
CBC 加密数据并返回 base64 格式的密文 * * @param inputBuf 要加密的数据 * @param p 数据填充方式 * * @return string base64 格式的密文 *
func (*AES) CBCEncryptToHexString ¶
CBC 加密数据并返回 hex 格式的密文 * * @param inputBuf 要加密的数据 * @param p 数据填充方式 * * @return string hex 格式的密文 *
func (*AES) DecryptFromBase64String ¶
解密 base64 格式的密文 * * @param inputBuf 要解密的 base64 编码密文字符 * @param p 数据填充方式 * * @return []byte 解密后的数据 * @return error 解密中出现的错误信息 *
func (*AES) DecryptFromHexString ¶
解密 hex 格式的密文 * * @param inputBuf 要解密的Hex编码密文字符 * @param p 数据填充方式 * * @return []byte 解密后的数据 * @return error 解密中出现的错误信息 *
func (*AES) EncryptToBase64String ¶
加密数据并返回 base64 格式的密文 * * @param inputBuf 要加密的数据 * @param p 数据填充方式 * * @return string base64 格式的密文 *
func (*AES) EncryptToHexString ¶
加密数据并返回 hex 格式的密文 * * @param inputBuf 要加密的数据 * @param p 数据填充方式 * * @return string hex 格式的密文 *
func (*AES) GetBlockSize ¶
获取 AES 加密块长度 * * @return int AES 加密块长度 *
type DES ¶
type DES struct {
// contains filtered or unexported fields
}
func NewDES ¶
creates and returns a new DES. The key argument should be the 8 bytes DES key. * The length of iv must be the same as the Block's block size. * * @param key the AES key * @param iv the iv key * * @return *AES AES instance * @return error Errors encountered
func (*DES) CBCDecrypt ¶
解密密文 * @param inputBuf 要解密的密文数据 * @param p 数据填充方式 * * @return []byte 明文
func (*DES) DESInit ¶
初始化 DES 实例,密钥必须 16 字节 * * @param key DES 加解密密钥 * @param iv 8 字节 CBC 初始化向量 * * @return error 遇到的错误 *
func (*DES) GetBlockSize ¶
获取 DES 加密块长度 * * @return int DES 加密块长度 *
type RSA ¶
type RSA struct { PublicKeyBytes []byte PrivateKeyBytes []byte // contains filtered or unexported fields }
func (*RSA) GenerateKeyWithBits ¶
func (*RSA) GeneratePublicKey ¶
func (*RSA) ParsePKCS1PrivateKey ¶
func (*RSA) ParsePKCS1PublicKey ¶
func (*RSA) PrivateKeyDecrypt ¶
私钥解密
type Sha ¶
type Sha struct{}
func (*Sha) Md5ToBase64String ¶
func (*Sha) Md5ToHexString ¶
func (*Sha) Sha1ToBase64String ¶
func (*Sha) Sha1ToHexString ¶
func (*Sha) Sha256ToBase64String ¶
func (*Sha) Sha256ToHexString ¶
func (*Sha) Sha512ToBase64String ¶
func (*Sha) Sha512ToHexString ¶
type TripleDES ¶
type TripleDES struct {
// contains filtered or unexported fields
}
func NewTripleDES ¶
creates and returns a new TripleDES. The key argument should be the TripleDES key, * either 8, 16, or 24 bytes to select TripleDES with 1 key, TripleDES with 2 key, * or TripleDES with 3 key. The length of iv must be the same as the Block's block size. * If an 8 bytes key, and it is the same as DES. * * @param key the TripleDES key * @param iv the iv key * * @return *TripleDES TripleDES instance * @return error Errors encountered
func (*TripleDES) CBCDecrypt ¶
解密密文 * @param inputBuf 要解密的密文数据 * @param p 数据填充方式 * * @return []byte 明文
func (*TripleDES) CBCDecryptFromBase64String ¶
* 解密密文
- @param inputStr 要解密的Base64编码密文数据
- @param p 数据填充方式
func (*TripleDES) GetBlock ¶
获取 TripleDES 使用的 cipher.Block * * @return cipher.Block TripleDES使用的block *
func (*TripleDES) GetBlockSize ¶
获取 TripleDES 加密块长度 * * @return int TripleDES 加密块长度 *
func (*TripleDES) TripleDESInit ¶
初始化 AES 实例,16, 24, 或 32 字节来选择 AES-128, AES-192, 或 AES-256 * * @param key AES 加解密密钥 * @param iv 16 字节 CBC 初始化向量 * * @return error 遇到的错误 *