Created
September 17, 2018 09:19
-
-
Save littlecxm/9e05ca91989caf3518aea5aca8df8885 to your computer and use it in GitHub Desktop.
test_ecb.go
This file contains hidden or 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
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