pkcs.go 377 B

1234567891011121314151617
  1. package yu_crypto
  2. func PKCS7Trimming(data []byte) []byte {
  3. return data[:len(data)-int(data[len(data)-1])]
  4. }
  5. func PKCS7Padding(data []byte, block int) []byte {
  6. j_pad := byte(block - len(data)%block)
  7. if j_pad < 1 {
  8. return data
  9. }
  10. j_buf := make([]byte, 0, j_pad)
  11. for j_i := byte(0); j_i < j_pad; j_i++ {
  12. j_buf = append(j_buf, j_pad)
  13. }
  14. return append(data, j_buf...)
  15. }