Documentation ¶
Index ¶
- Constants
- Variables
- func AESCbcPkcs7PaddingDecrypt(crypted, key []byte) ([]byte, error)
- func AESCbcPkcs7PaddingEncrypt(origData, key []byte) ([]byte, error)
- func AESCfbDecrypt(ciphertext, key []byte) (plaintext []byte, err error)
- func AESCfbEncrypt(text, key []byte) (ciphertext []byte, err error)
- func AESEcbPkcs7PaddingDecrypt(src, key []byte) ([]byte, error)
- func AESEcbPkcs7PaddingEncrypt(src, key []byte) ([]byte, error)
- func AESPKCS5Padding(ciphertext []byte, blockSize int) []byte
- func AESPKCS5UnPadding(origData []byte) []byte
- func BlowfishDecrypt(dataToDecrypt, key []byte) []byte
- func BlowfishEncrypt(dataToEncrypt, key []byte) []byte
- func CaesarDecrypt(n int, data []byte) ([]byte, error)
- func CaesarEncrypt(n int, data []byte) ([]byte, error)
- func DESDecrypt(crypted, key []byte) ([]byte, error)
- func DESEncrypt(src, key []byte) ([]byte, error)
- func DESPKCS5Padding(ciphertext []byte, blockSize int) []byte
- func DESPKCS5UnPadding(origData []byte) []byte
- func GenerateAES256RandomBase64String() (string, error)
- func GenerateAES256RandomBytes() ([]byte, error)
- func GenerateRSAKeyPairToFile(privateKeyFilepath, publicKeyFilepath string, keySize int) error
- func KeyTo24Padding(key []byte) ([]byte, error)
- func NewECBDecrypter(b cipher.Block) cipher.BlockMode
- func NewECBEncrypter(b cipher.Block) cipher.BlockMode
- func PKCS5Padding(data []byte, blockSize int) ([]byte, error)
- func PKCS5UnPadding(data []byte) ([]byte, error)
- func PKCS7Padding(b []byte, blocksize int) ([]byte, error)
- func PKCS7UnPadding(b []byte) ([]byte, error)
- func ReadRSAPrivateKeyFromByte(privateKey []byte) (*rsa.PrivateKey, error)
- func ReadRSAPrivateKeyFromFile(privateKeyFilepath string) (*rsa.PrivateKey, error)
- func ReadRSAPublicKeyFromByte(publicKey []byte) (*rsa.PublicKey, error)
- func ReadRSAPublicKeyFromFile(publicKeyFilepath string) (*rsa.PublicKey, error)
- func Sha256HexEecode(s string) string
- func TripleDesEcbDecrypt(src, key []byte) ([]byte, error)
- func TripleDesEcbEncrypt(src, key []byte) ([]byte, error)
- func ZerosPadding(src []byte, blockSize int) []byte
- func ZerosUnPadding(src []byte) []byte
- type RSA
Constants ¶
const ( // TripleDESKeyingOption1 means all three keys are independent TripleDESKeyingOption1 = 24 // TripleDESKeyingOption2 means K1 and K2 are independent, and K3 = K1 TripleDESKeyingOption2 = 16 // TripleDESKeyingOption3 means All three keys are identical, i.e. K1 = K2 = K3 TripleDESKeyingOption3 = 8 )
Variables ¶
var ( // ErrDivisionByZero returns because the input may cause division by zero ErrDivisionByZero = errors.New("division by zero") // ErrKeyLength returned because input key length is not qualified ErrKeyLength = errors.New("key length error, must be 16 or 24") )
var ( // ErrHashTypeNotAllowed represents that input has type is not allowed ErrHashTypeNotAllowed = errors.New("Hash algorithm must be one of md5, sha1, sha256, sha512") // ErrNotPEMEncoded represents that key are not encoded by PEM ErrNotPEMEncoded = errors.New("Not PEM-encoded") // ErrUnkownKeyType represents that key file type are not RSA ErrUnkownKeyType = errors.New("Unknown key type") // ErrNotRSAPublicKey represents that key is not an RSA public key format ErrNotRSAPublicKey = errors.New("Not an RSA public format") )
Functions ¶
func AESCbcPkcs7PaddingDecrypt ¶
AESCbcPkcs7PaddingDecrypt AES decrypttion with CBC and PKCS7Padding Key length: 16, 24, 32 bytes => AES-128, AES-192, AES-256
func AESCbcPkcs7PaddingEncrypt ¶
AESCbcPkcs7PaddingEncrypt AES encrypttion with CBC and PKCS7Padding
func AESCfbDecrypt ¶
AESCfbDecrypt returns the decrypt string of the crypted string by CFB AES. According by https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
func AESCfbEncrypt ¶
AESCfbEncrypt returns the encrypt string of the crypted string by CFB AES. According by https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
func AESEcbPkcs7PaddingDecrypt ¶
AesECBDecrypt
func AESEcbPkcs7PaddingEncrypt ¶
AesECBEncrypt
func AESPKCS5Padding ¶
AESPKCS5Padding PKCS5padding for AES
func AESPKCS5UnPadding ¶
AESPKCS5UnPadding PKCS5UnPadding for AES
func BlowfishDecrypt ¶
BlowfishDecrypt blowfish decryption
func BlowfishEncrypt ¶
BlowfishEncrypt blowfish encryption
func CaesarDecrypt ¶
CaesarDecrypt but it can handles numbers and any ASCII codes. recording by: https://en.wikipedia.org/wiki/Caesar_cipher
func CaesarEncrypt ¶
CaesarEncrypt but it can handles numbers and any ASCII codes. recording by: https://en.wikipedia.org/wiki/Caesar_cipher
func DESPKCS5Padding ¶
func DESPKCS5UnPadding ¶
func GenerateAES256RandomBase64String ¶
GenerateAES256RandomBase64String returns a base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.
func GenerateAES256RandomBytes ¶
GenerateAES256RandomBites returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.
func GenerateRSAKeyPairToFile ¶
GenerateRSAKeyPairToFile creates random RSA private and public key pairs then saves them in files.
func KeyTo24Padding ¶
KeyTo24Padding returns 24 bytes length of key.
func NewECBDecrypter ¶
NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.
func NewECBEncrypter ¶
NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.
func PKCS5UnPadding ¶
PKCS5UnPadding returns a list of bytes which has removed padding bytes in it.
func PKCS7Padding ¶
AESPKCS7Padding right-pads the given byte slice with 1 to n bytes, where n is the block size. The size of the result is x times n, where x is at least 1.
func PKCS7UnPadding ¶
AESPKCS7UnPadding validates and unpads data from the given bytes slice. The returned value will be 1 to n bytes smaller depending on the amount of padding, where n is the block size.
func ReadRSAPrivateKeyFromByte ¶
func ReadRSAPrivateKeyFromByte(privateKey []byte) (*rsa.PrivateKey, error)
ReadRSAPrivateKeyFromByte returns the RSA private key from byte array.
func ReadRSAPrivateKeyFromFile ¶
func ReadRSAPrivateKeyFromFile(privateKeyFilepath string) (*rsa.PrivateKey, error)
ReadRSAPrivateKeyFromFile returns the RSA private key from file.
func ReadRSAPublicKeyFromByte ¶
ReadRSAPublicKeyFromByte returns the RSA public key from byte array.
func ReadRSAPublicKeyFromFile ¶
ReadRSAPublicKeyFromFile returns the RSA public key from file.
func Sha256HexEecode ¶
Sha256HexEecode returns a hex encoded string of sha256 hashed string.
func TripleDesEcbDecrypt ¶
TripleDesEcbDecrypt returns the decrypt string of the crypted string by ECB 3DES. The input key must bigger or equal to 8 bytes. According by https://en.wikipedia.org/wiki/Triple_DES to implement.
func TripleDesEcbEncrypt ¶
TripleDesEcbEncrypt returns the encrypt string of the plantext by ECB 3DES. The input key must bigger or equal to 8 bytes and must be a multiple of 8. According by https://en.wikipedia.org/wiki/Triple_DES to implement.
func ZerosUnPadding ¶
Types ¶
type RSA ¶
type RSA struct {
// contains filtered or unexported fields
}
RSA is the RSA hash algorithm instance.