Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Mar 20, 2023
1 parent d1e1e17 commit d7ffa5a
Showing 1 changed file with 7 additions and 34 deletions.
41 changes: 7 additions & 34 deletions tool/padding.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ func (this Padding) PKCS7Padding(text []byte, blockSize int) []byte {
return text
}

// 补位 blockSize 值
paddingSize := blockSize - n%blockSize

// 为 0 时补位 blockSize 值
if paddingSize == 0 {
paddingSize = blockSize
}

paddingText := bytes.Repeat([]byte{byte(paddingSize)}, paddingSize)

return append(text, paddingText...)
Expand Down Expand Up @@ -76,13 +71,8 @@ func (this Padding) ZeroPadding(text []byte, blockSize int) []byte {
return text
}

// 补位 blockSize 值
paddingSize := blockSize - n%blockSize

// 为 0 时补位 blockSize 值
if paddingSize == 0 {
paddingSize = blockSize
}

paddingText := bytes.Repeat([]byte{byte(0)}, paddingSize)

return append(text, paddingText...)
Expand Down Expand Up @@ -115,16 +105,11 @@ func (this Padding) X923Padding(text []byte, blockSize int) []byte {
return text
}

// 补位 blockSize 值
paddingSize := blockSize - n%blockSize

// 为 0 时补位 blockSize 值
if paddingSize == 0 {
paddingSize = blockSize
}

paddingText := bytes.Repeat([]byte{byte(0)}, paddingSize - 1)
text = append(text, paddingText...)

text = append(text, paddingText...)
text = append(text, byte(paddingSize))

return text
Expand Down Expand Up @@ -157,13 +142,9 @@ func (this Padding) ISO10126Padding(text []byte, blockSize int) []byte {
return text
}

// 补位 blockSize 值
paddingSize := blockSize - n%blockSize

// 为 0 时补位 blockSize 值
if paddingSize == 0 {
paddingSize = blockSize
}

for i := 0; i < paddingSize - 1; i++ {
text = append(text, this.RandomBytes(1)...)
}
Expand Down Expand Up @@ -200,13 +181,9 @@ func (this Padding) ISO7816_4Padding(text []byte, blockSize int) []byte {
return text
}

// 补位 blockSize 值
paddingSize := blockSize - n%blockSize

// 为 0 时补位 blockSize 值
if paddingSize == 0 {
paddingSize = blockSize
}

text = append(text, 0x80)

paddingText := bytes.Repeat([]byte{0x00}, paddingSize - 1)
Expand Down Expand Up @@ -239,13 +216,9 @@ func (this Padding) TBCPadding(text []byte, blockSize int) []byte {
return text
}

// 补位 blockSize 值
paddingSize := blockSize - n%blockSize

// 为 0 时补位 blockSize 值
if paddingSize == 0 {
paddingSize = blockSize
}

lastBit := text[n - 1] & 0x1

var paddingByte byte
Expand Down

0 comments on commit d7ffa5a

Please sign in to comment.