From 5af01add6457920ec6fe1e15adf3d1911d9463e2 Mon Sep 17 00:00:00 2001 From: ycc Date: Thu, 15 Dec 2022 21:59:31 +0100 Subject: [PATCH] use simple sign asym --- asymcrypt.go | 8 ++++---- asymcrypt_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/asymcrypt.go b/asymcrypt.go index 7b2c2ce..070bf37 100644 --- a/asymcrypt.go +++ b/asymcrypt.go @@ -100,7 +100,7 @@ func AsymDecryptArmored(PrivateKey string, data []byte) ([]byte, error) { return []byte(decrypted), err } -func AsymEncryptAndSign(PublicEncryptionKey string, PrivateSignatureKey string, data []byte) ([]byte, []byte, error) { +func AsymEncryptAndSign_helpers(PublicEncryptionKey string, PrivateSignatureKey string, data []byte) ([]byte, []byte, error) { pub, err := base64.StdEncoding.DecodeString(PublicEncryptionKey) if err != nil { log.Error().Msg("Message encryption and sign b64 failed") @@ -116,7 +116,7 @@ func AsymEncryptAndSign(PublicEncryptionKey string, PrivateSignatureKey string, return []byte(encrypted), []byte(signature), err } -func AsymDecryptAndCheck(MyPrivateEncryptionKey string, MyContactPublicKey string, data []byte, Signature []byte) (DecryptedMessage []byte, err error) { +func AsymDecryptAndCheck_helpers(MyPrivateEncryptionKey string, MyContactPublicKey string, data []byte, Signature []byte) (DecryptedMessage []byte, err error) { priv, err := base64.StdEncoding.DecodeString(MyPrivateEncryptionKey) if err != nil { log.Error().Msg("Message decryption and sign b64 failed") @@ -193,7 +193,7 @@ func createPublicKeyRing(publicKey string) (*crypto.KeyRing, error) { return publicKeyRing, nil } -func AsymEncryptAndSign2(PublicEncryptionKey string, PrivateSignatureKey string, data []byte) ([]byte, []byte, error) { +func AsymEncryptAndSign(PublicEncryptionKey string, PrivateSignatureKey string, data []byte) ([]byte, []byte, error) { pub, err := base64.StdEncoding.DecodeString(PublicEncryptionKey) if err != nil { log.Error().Msg("Message encryption and sign b64 failed") @@ -210,7 +210,7 @@ func AsymEncryptAndSign2(PublicEncryptionKey string, PrivateSignatureKey string, return ciphertext.GetBinary(), signature, err } -func AsymDecryptAndCheck2(MyPrivateEncryptionKey string, MyContactPublicKey string, data []byte, Signature []byte) (DecryptedMessage []byte, err error) { +func AsymDecryptAndCheck(MyPrivateEncryptionKey string, MyContactPublicKey string, data []byte, Signature []byte) (DecryptedMessage []byte, err error) { priv, err := base64.StdEncoding.DecodeString(MyPrivateEncryptionKey) if err != nil { log.Error().Msg("Message decryption and sign b64 failed") diff --git a/asymcrypt_test.go b/asymcrypt_test.go index 034b9cc..9d09095 100644 --- a/asymcrypt_test.go +++ b/asymcrypt_test.go @@ -97,11 +97,11 @@ func TestAsymEncryptDecryptSigned(t *testing.T) { func TestAsymEncryptDecryptSigned2(t *testing.T) { kp := NewKeyPair() foo := "!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~" - encMess, sign, err := AsymEncryptAndSign2(kp.Public, kp.Private, []byte(foo)) + encMess, sign, err := AsymEncryptAndSign(kp.Public, kp.Private, []byte(foo)) if err != nil { log.Println(err.Error()) } - decMess, err2 := AsymDecryptAndCheck2(kp.Private, kp.Public, encMess, sign) + decMess, err2 := AsymDecryptAndCheck(kp.Private, kp.Public, encMess, sign) if err2 != nil { log.Println(err2.Error()) } @@ -144,7 +144,7 @@ func TestFlutterDecode(t *testing.T) { log.Println(err.Error()) } println(string(decMsg)) - decMsg, err = AsymDecryptAndCheck2(base64.StdEncoding.EncodeToString(priv), base64.StdEncoding.EncodeToString(pub), msg, sign) + decMsg, err = AsymDecryptAndCheck(base64.StdEncoding.EncodeToString(priv), base64.StdEncoding.EncodeToString(pub), msg, sign) if err != nil { log.Println(err.Error()) } @@ -163,7 +163,7 @@ func TestFlutterEncode(t *testing.T) { fmt.Println("Err") } - encMess, sign2, err := AsymEncryptAndSign2(base64.StdEncoding.EncodeToString(pub), base64.StdEncoding.EncodeToString(priv), []byte("Hello")) + encMess, sign2, err := AsymEncryptAndSign(base64.StdEncoding.EncodeToString(pub), base64.StdEncoding.EncodeToString(priv), []byte("Hello")) if err != nil { log.Println(err.Error()) }