Last active
August 29, 2015 14:05
-
-
Save icchan/122363b864e296f93bce to your computer and use it in GitHub Desktop.
Function to decrypt an aes encrypted and base64 encoded string
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
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