package rsa import ( "testing" ) /*const ( priKey = ` -----BEGIN RSA PRIVATE KEY----- MFECAQACDQDt0G4B3JeeHjLWvX0CAwEAAQINANmKZncRf2SzCt/qiQIHAP1hu7hC NwIHAPBFhAcz6wIHAMKsRD3dIQIGDn4S7aBLAgY5OcfnuCQ= -----END RSA PRIVATE KEY----- ` pubKey = ` -----BEGIN PUBLIC KEY----- MCgwDQYJKoZIhvcNAQEBBQADFwAwFAINAO3QbgHcl54eMta9fQIDAQAB -----END PUBLIC KEY----- ` )*/ var priKey string var pubKey string func TestGenerateKey(t *testing.T) { pri, pub, err := GenerateKey(1024) if err != nil { t.Error(err) } priKey = string(pri) pubKey = string(pub) } func TestRSA(t *testing.T) { msg := "1" cipher, err := Encrypt([]byte(msg), []byte(pubKey)) if err != nil { t.Error(err) t.FailNow() } ori, err := Decrypt(cipher, []byte(priKey)) if err != nil { t.Error(err) t.FailNow() } if string(ori) != msg { t.FailNow() } } func BenchmarkRSA(b *testing.B) { msg := "1" cipher, err := Encrypt([]byte(msg), []byte(pubKey)) if err != nil { b.Error(err) b.FailNow() } for i := 0; i < b.N; i++ { if _, err := Decrypt(cipher, []byte(priKey)); err != nil { b.Error(err) b.FailNow() } } }