crypto

package
v0.0.0-...-0c08822 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ISO78164Padding = ISO9791Method2Padding

ISO78164Padding ISO/IEC 7816-4:2005[9] is identical to the bit padding scheme, applied to a plain text of N bytes. This means in practice that the first byte is a mandatory byte valued '80' (Hexadecimal) followed, if needed, by 0 to N − 1 bytes set to '00', until the end of the block is reached. ISO/IEC 7816-4 itself is a communication standard for smart cards containing a file system, and in itself does not contain any cryptographic specifications.

View Source
var ISO78164UnPadding = ISO9791Method2UnPadding

ZeroPadding See https://en.wikipedia.org/wiki/Data_source_name

View Source
var ZeroUnPadding = ISO9791Method1UnPadding

Functions

func ANSIX923Padding

func ANSIX923Padding(s []byte, block int) []byte

ANSIX923Padding In ANSI X9.23, between 1 and 8 bytes are always added as padding. The block is padded with random bytes (although many implementations use 00) and the last byte of the block is set to the number of bytes added.[6] Example: In the following example the block size is 8 bytes, and padding is required for 4 bytes (in hexadecimal format) ... | DD DD DD DD DD DD DD DD | DD DD DD DD 00 00 00 04 | See https://en.wikipedia.org/wiki/Padding_(cryptography)#ANSI_X9.23

func ANSIX923UnPadding

func ANSIX923UnPadding(s []byte, block int) ([]byte, error)

func AesDecrypt

func AesDecrypt(ciphertext, key []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(plaintext, key []byte) ([]byte, error)

AesEncrypt key 长度 16, 24, 32 分别对应 AES-128, AES-192, AES-256

func ISO9791Method1Padding

func ISO9791Method1Padding(s []byte, block int) []byte

ISO9791Method1Padding the data string D to be input to the MAC algorithm shall be right-padded with as few (possible none) '0' bits as necessary to obtain a data string whose length(in bits) is a positive integer multiple of n. NOTE 1 MAC algorithm using Padding Method 1 may be subject to trivial forgery attacks. 2 If the data string is empty, Padding Method1 specifies that it is right-padded with n '0' bits. See https://en.wikipedia.org/wiki/ISO/IEC_9797-1#Padding_method_1

func ISO9791Method1UnPadding

func ISO9791Method1UnPadding(s []byte, block int) []byte

func ISO9791Method2Padding

func ISO9791Method2Padding(s []byte, block int) []byte

ISO9791Method2Padding the data string D to be input to the MAC algorithm shall be right-padded with a single '1' bit. The resulting string shall then be right-padded with as few (possible none) '0' bits as necessary to obtain a data string whose length(in bits) is a positive integer multiple of n. See https://en.wikipedia.org/wiki/ISO/IEC_9797-1#Padding_method_2

func ISO9791Method2UnPadding

func ISO9791Method2UnPadding(s []byte, block int) ([]byte, error)

func ISO9791Method3Padding

func ISO9791Method3Padding(s []byte, block int) []byte

ISO9791Method3Padding the data string D to be input to the MAC algorithm shall be right-padded with as few (possible none) '0' bits as necessary to obtain a data string whose length(in bits) is a positive integer multiple of n. The resulting string shall then be left-padded with a block L. The block L consists of the binary representation of the length(in bits) Ld of the unpadded data string D, left-padded with as few (possible none) '0' bits as necessary to obtain an n-bit block. The right-most bit of the block L corresponds to the least significant bit of the binary representation of Ld. NOTE 1 Padding Method 3 is not suitable for use in situations where the length of the data string is not available prior to the start of the MAC calculation. See https://en.wikipedia.org/wiki/ISO/IEC_9797-1#Padding_method_2

func ISO9791Method3UnPadding

func ISO9791Method3UnPadding(s []byte, block int) ([]byte, error)

func PKCS5Padding

func PKCS5Padding(s []byte) []byte

PKCS5Padding PKCS#5 padding is identical to PKCS#7 padding, except that it has only been defined for block ciphers that use a 64-bit (8-byte) block size. In practice the two can be used interchangeably.

func PKCS5UnPadding

func PKCS5UnPadding(s []byte) ([]byte, error)

func PKCS7Padding

func PKCS7Padding(s []byte, block int) []byte

PKCS7Padding Padding is in whole bytes. The value of each added byte is the number of bytes that are added, i.e. N bytes, each of value N are added. The number of bytes added will depend on the block boundary to which the message needs to be extended. The padding will be one of: 01 02 02 03 03 03 04 04 04 04 05 05 05 05 05 06 06 06 06 06 06 etc. This padding method (as well as the previous two) is well-defined if and only if N is less than 256. Example: In the following example the block size is 8 bytes and padding is required for 4 bytes ... | DD DD DD DD DD DD DD DD | DD DD DD DD 04 04 04 04 | If the length of the original data is an integer multiple of the block size B, then an extra block of bytes with value B is added. This is necessary so the deciphering algorithm can determine with certainty whether the last byte of the last block is a pad byte indicating the number of padding bytes added or part of the plaintext message. Consider a plaintext message that is an integer multiple of B bytes with the last byte of plaintext being 01. With no additional information, the deciphering algorithm will not be able to determine whether the last byte is a plaintext byte or a pad byte. However, by adding B bytes each of value B after the 01 plaintext byte, the deciphering algorithm can always treat the last byte as a pad byte and strip the appropriate number of pad bytes off the end of the ciphertext; said number of bytes to be stripped based on the value of the last byte. See https://tools.ietf.org/html/rfc5652#section-6.3

func PKCS7UnPadding

func PKCS7UnPadding(s []byte, block int) ([]byte, error)

Types

type GoogleAuth

type GoogleAuth struct {
}

func NewGoogleAuth

func NewGoogleAuth() *GoogleAuth

func (*GoogleAuth) GetCode

func (g *GoogleAuth) GetCode(secret string) (string, error)

GetCode 获取动态码

func (*GoogleAuth) GetQrcode

func (g *GoogleAuth) GetQrcode(user, secret string) string

GetQrcode 获取动态码二维码内容

func (*GoogleAuth) GetQrcodeUrl

func (g *GoogleAuth) GetQrcodeUrl(user, secret string) string

GetQrcodeUrl 获取动态码二维码图片地址,这里是第三方二维码api

func (*GoogleAuth) GetSecret

func (g *GoogleAuth) GetSecret() (string, error)

GetSecret 获取秘钥

func (*GoogleAuth) VerifyCode

func (g *GoogleAuth) VerifyCode(secret, code string) (bool, error)

VerifyCode 验证动态码

Jump to

Keyboard shortcuts

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