padding.go 399 B

1234567891011121314151617
  1. package aes
  2. import (
  3. "bytes"
  4. )
  5. func pkcs5Padding(cipherText []byte, blockSize int) []byte {
  6. padding := blockSize - len(cipherText)%blockSize
  7. padText := bytes.Repeat([]byte{byte(padding)}, padding)
  8. return append(cipherText, padText...)
  9. }
  10. func pkcs5UnPadding(decrypted []byte) []byte {
  11. length := len(decrypted)
  12. unPadding := int(decrypted[length-1])
  13. return decrypted[:(length - unPadding)]
  14. }