1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00

加密包装

This commit is contained in:
2022-03-27 10:21:30 +08:00
parent 22f41aeeeb
commit 12865abe26
14 changed files with 1068 additions and 0 deletions

38
crypto/des_test.go Normal file
View File

@ -0,0 +1,38 @@
package crypto_test
import (
"crypto/aes"
"crypto/des"
"encoding/hex"
"testing"
"github.com/charlienet/go-mixed/crypto"
)
func TestDes(t *testing.T) {
key, _ := hex.DecodeString("0123456789ABCDEF")
msg, _ := hex.DecodeString("F0A2B07E64DD2C25")
c, err := crypto.Des(key).ECB().Encrypt(msg)
t.Log(hex.EncodeToString(c), err)
c, err = crypto.Des(key).Cbc().Encrypt(msg)
t.Log(hex.EncodeToString(c), err)
d, err := crypto.Des(key).Cbc().Decrypt(c)
t.Log(hex.EncodeToString(d), err)
}
func TestTripleDES(t *testing.T) {
key, _ := hex.DecodeString("0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF")
block, err := des.NewTripleDESCipher(key)
t.Log(block, err, block.BlockSize())
}
func TestAes(t *testing.T) {
t.Log(aes.BlockSize)
key, _ := hex.DecodeString("0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF")
msg, _ := hex.DecodeString("F0A2B07E64DD2C25")
c, err := crypto.Aes(key).ECB().Encrypt(msg)
t.Log(hex.EncodeToString(c), err)
}