2016-02-03 11:46:12 +08:00
|
|
|
package pcrypto
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/aes"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-02-18 11:42:31 +08:00
|
|
|
func TestEncrypto(t *testing.T) {
|
2016-02-03 11:46:12 +08:00
|
|
|
pp := new(Pcrypto)
|
|
|
|
pp.Init([]byte("Hana"))
|
|
|
|
res, err := pp.Encrypto([]byte("Just One Test!"))
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("[%x]\n", res)
|
|
|
|
}
|
|
|
|
|
2016-02-18 11:42:31 +08:00
|
|
|
func TestDecrypto(t *testing.T) {
|
2016-02-03 11:46:12 +08:00
|
|
|
pp := new(Pcrypto)
|
|
|
|
pp.Init([]byte("Hana"))
|
|
|
|
res, err := pp.Encrypto([]byte("Just One Test!"))
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err = pp.Decrypto(res)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("[%s]\n", string(res))
|
|
|
|
}
|
|
|
|
|
2016-02-18 11:42:31 +08:00
|
|
|
func TestPKCS7Padding(t *testing.T) {
|
2016-02-03 11:46:12 +08:00
|
|
|
ltt := []byte("Test_PKCS7Padding")
|
|
|
|
ltt = PKCS7Padding(ltt, aes.BlockSize)
|
|
|
|
fmt.Printf("[%x]\n", (ltt))
|
|
|
|
}
|
|
|
|
|
2016-02-18 11:42:31 +08:00
|
|
|
func TestPKCS7UnPadding(t *testing.T) {
|
2016-02-03 11:46:12 +08:00
|
|
|
ltt := []byte("Test_PKCS7Padding")
|
|
|
|
ltt = PKCS7Padding(ltt, aes.BlockSize)
|
|
|
|
ltt = PKCS7UnPadding(ltt)
|
|
|
|
fmt.Printf("[%x]\n", ltt)
|
|
|
|
}
|