Skip to content

Instantly share code, notes, and snippets.

@Grrrben
Created November 1, 2018 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grrrben/e74d0becb95aca59a1661a0745532106 to your computer and use it in GitHub Desktop.
Save Grrrben/e74d0becb95aca59a1661a0745532106 to your computer and use it in GitHub Desktop.
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