Skip to content

Instantly share code, notes, and snippets.

@littlecxm
Created September 17, 2018 09:19
Show Gist options
  • Save littlecxm/9e05ca91989caf3518aea5aca8df8885 to your computer and use it in GitHub Desktop.
Save littlecxm/9e05ca91989caf3518aea5aca8df8885 to your computer and use it in GitHub Desktop.
test_ecb.go
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"encoding/hex"
"fmt"
)
func main() {
fmt.Println("AesECB ---------------------------------")
testAesECB()
}
func testAesECB() {
txt := "abcdefgh12345678"
key := "abcdefgh12345678"
dest := make([]byte, (len(txt)/len(key)+1)*len(key))
aesCipher, _ := aes.NewCipher([]byte(key))
encrypter := cipher.NewECBEncrypter(aesCipher)
encrypter.CryptBlocks(dest, []byte(txt))
fmt.Println(hex.EncodeToString([]byte(txt)))
fmt.Println(hex.EncodeToString([]byte(key)))
fmt.Println(dest)
fmt.Println(hex.EncodeToString(dest))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment