mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
加密包装
This commit is contained in:
38
crypto/des_test.go
Normal file
38
crypto/des_test.go
Normal 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)
|
||||
}
|
Reference in New Issue
Block a user