Created
November 1, 2018 17:59
-
-
Save Grrrben/e74d0becb95aca59a1661a0745532106 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestEncryptDecrypt(t *testing.T) { | |
henk, _ := NewRsaIdentity() | |
ingrid, _ := NewRsaIdentity() | |
// a message from Henk to Ingrid | |
msg := []byte("Die uitkeringstrekkers pikken al onze banen in.") | |
// Lets encrypt it, we want to sent it to Ingrid, thus, we use her public key. | |
encryptedMessage, err := henk.Encrypt(msg, ingrid.public) | |
if err != nil { | |
t.Errorf("Unable to encrypt Henk's message for Ingrid; %s", err) | |
} | |
plainTextMessage, err := ingrid.Decrypt(encryptedMessage) | |
if err != nil { | |
t.Errorf("Unable to decrypt Henk's message for Ingrid; %s", err) | |
} | |
if !bytes.Equal(plainTextMessage[:], msg[:]) { | |
t.Error("Unable to decrypt Henk's message for Ingrid; byte arrays are not the same") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment