Skip to content

Instantly share code, notes, and snippets.

@jasonkeene
Created January 3, 2015 21:57
Show Gist options
  • Save jasonkeene/714ad2c586cc7851df82 to your computer and use it in GitHub Desktop.
Save jasonkeene/714ad2c586cc7851df82 to your computer and use it in GitHub Desktop.
// Excerpt from Practical Cryptography With Go
// https://leanpub.com/gocrypto/read#leanpub-auto-block-padding
// Pad applies the PKCS #7 padding scheme on the buffer.
func Pad(in []byte) []byte {
padding := 16 - (len(in) % 16)
if padding == 0 {
padding = 16
}
for i := 0; i < padding; i++ {
in = append(in, byte(padding))
}
return in
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment