/
crypto_padding.go
56 lines (50 loc) · 1.67 KB
/
crypto_padding.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cryptox
import "bytes"
type FuncPadding func(ciphertext []byte, blockSize int) []byte
type FuncUnPadding func(origData []byte) []byte
func PKCS7Padding(cipherText []byte, blockSize int) []byte {
padding := blockSize - len(cipherText)%blockSize
padText := bytes.Repeat([]byte{byte(padding)}, padding)
return append(cipherText, padText...)
}
func PKCS7UnPadding(origData []byte) []byte {
length := len(origData)
unPadding := int(origData[length-1])
return origData[:(length - unPadding)]
}
func ZeroPadding(ciphertext []byte, blockSize int) []byte {
//padding := blockSize - len(ciphertext)%blockSize
//padtext := bytes.Repeat([]byte{byte(padding)}, padding)
//return append(ciphertext, padtext...)
return nil
}
func ZeroUnPadding(origData []byte) []byte {
//length := len(origData)
//unpadding := int(origData[length-1])
//return origData[:(length - unpadding)]
return nil
}
func Iso10126Padding(ciphertext []byte, blockSize int) []byte {
//padding := blockSize - len(ciphertext)%blockSize
//padtext := bytes.Repeat([]byte{byte(padding)}, padding)
//return append(ciphertext, padtext...)
return nil
}
func Iso10126UnPadding(origData []byte) []byte {
//length := len(origData)
//unpadding := int(origData[length-1])
//return origData[:(length - unpadding)]
return nil
}
func Ansix923Padding(ciphertext []byte, blockSize int) []byte {
//padding := blockSize - len(ciphertext)%blockSize
//padtext := bytes.Repeat([]byte{byte(padding)}, padding)
//return append(ciphertext, padtext...)
return nil
}
func Ansix923UnPadding(origData []byte) []byte {
//length := len(origData)
//unpadding := int(origData[length-1])
//return origData[:(length - unpadding)]
return nil
}