use simple sign asym
This commit is contained in:
parent
684d444bc8
commit
5af01add64
@ -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")
|
||||
|
@ -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())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user