Created
March 22, 2018 19:32
-
-
Save fourst4r/4f1c93918755871238c98921354ac062 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Useful for AES encryption. | |
// Pad the ciphertext with zeros until it is of length blockSize. | |
func ZerosPad(ciphertext []byte, blockSize int) []byte { | |
// determine number of zeros to add | |
padLen := blockSize - (len(ciphertext) % blockSize) | |
padText := bytes.Repeat([]byte{0}, padLen) | |
ciphertext = append(ciphertext, padText...) | |
return ciphertext | |
} | |
// Trim the trailing zeros from ciphertext. | |
func ZerosUnpad(ciphertext []byte) []byte { | |
return bytes.TrimRight(ciphertext, string(byte(0))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment