Skip to content

Instantly share code, notes, and snippets.

@icchan
Last active August 29, 2015 14:05
Show Gist options
  • Save icchan/122363b864e296f93bce to your computer and use it in GitHub Desktop.
Save icchan/122363b864e296f93bce to your computer and use it in GitHub Desktop.
Function to decrypt an aes encrypted and base64 encoded string
func decrypter(crypto string, keyString string) string {
paddedKey := fmt.Sprintf("%-16s", keyString) // 16 bytes
key := []byte(paddedKey)
bc, err := aes.NewCipher(key)
if err != nil {
fmt.Println(err)
}
src, _ := hex.DecodeString(crypto)
var dst = make([]byte, len(src)) // final output array
blockSize := bc.BlockSize() // size of one block
loops := len(src) / blockSize // number of times to loop
// loop thru and decrypt each block
for i := 0; i < loops; i++ {
start := i * blockSize
end := (i * blockSize) + blockSize
bc.Decrypt(dst[start:end], src[start:end])
}
return string(dst)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment