use simple sign asym

This commit is contained in:
ycc 2022-12-15 21:59:31 +01:00
parent 684d444bc8
commit 5af01add64
2 changed files with 8 additions and 8 deletions

View File

@ -100,7 +100,7 @@ func AsymDecryptArmored(PrivateKey string, data []byte) ([]byte, error) {
return []byte(decrypted), err 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) pub, err := base64.StdEncoding.DecodeString(PublicEncryptionKey)
if err != nil { if err != nil {
log.Error().Msg("Message encryption and sign b64 failed") 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 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) priv, err := base64.StdEncoding.DecodeString(MyPrivateEncryptionKey)
if err != nil { if err != nil {
log.Error().Msg("Message decryption and sign b64 failed") log.Error().Msg("Message decryption and sign b64 failed")
@ -193,7 +193,7 @@ func createPublicKeyRing(publicKey string) (*crypto.KeyRing, error) {
return publicKeyRing, nil 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) pub, err := base64.StdEncoding.DecodeString(PublicEncryptionKey)
if err != nil { if err != nil {
log.Error().Msg("Message encryption and sign b64 failed") log.Error().Msg("Message encryption and sign b64 failed")
@ -210,7 +210,7 @@ func AsymEncryptAndSign2(PublicEncryptionKey string, PrivateSignatureKey string,
return ciphertext.GetBinary(), signature, err 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) priv, err := base64.StdEncoding.DecodeString(MyPrivateEncryptionKey)
if err != nil { if err != nil {
log.Error().Msg("Message decryption and sign b64 failed") log.Error().Msg("Message decryption and sign b64 failed")

View File

@ -97,11 +97,11 @@ func TestAsymEncryptDecryptSigned(t *testing.T) {
func TestAsymEncryptDecryptSigned2(t *testing.T) { func TestAsymEncryptDecryptSigned2(t *testing.T) {
kp := NewKeyPair() kp := NewKeyPair()
foo := "!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~" 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 { if err != nil {
log.Println(err.Error()) 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 { if err2 != nil {
log.Println(err2.Error()) log.Println(err2.Error())
} }
@ -144,7 +144,7 @@ func TestFlutterDecode(t *testing.T) {
log.Println(err.Error()) log.Println(err.Error())
} }
println(string(decMsg)) 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 { if err != nil {
log.Println(err.Error()) log.Println(err.Error())
} }
@ -163,7 +163,7 @@ func TestFlutterEncode(t *testing.T) {
fmt.Println("Err") 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 { if err != nil {
log.Println(err.Error()) log.Println(err.Error())
} }