Cet exemple utilise les algorithmes Argon2d, ed25519 et AES avec les composants TArgon2KeyDerivation, TECCEncSign et TAESEncryption.
Alice veut envoyer un message à Bob, donc elle possède sa clé privée (il utilise l’algorithme ed25519).
Le mot de passe peut être demandé à Alice en utilisant une boîte de dialogue.
Alice utilise la fonction suivante pour chiffrer un message à Bob :
function EncryptMessageToBob(password: string; input: string; BobPublicKey: string): string; var aesKey: string; eccCipher, aesCipher : string; begin Argon2.StringSalt := '0123456789012345'; Argon2.outputFormat := raw; aesKey := Argon2.GenerateKey(password); ECC.PublicKey := BobPublicKey; eccCipher := ecc.Encrypt(aesKey); aes.Key := aesKey; aesCipher := aes.Encrypt(input); Result := eccCipher + '+' + aesCipher; end;
Pour déchiffrer le message d’Alice, Bob utilise la fonction suivante :
function DecryptMessageFromAlice(input: string; BobPrivateKey: string): string; var eccCipher, aesCipher: string; aesKey: string; begin eccCipher := input.subString(0, Pos('+', input) - 1); aesCipher := input.subString(Pos('+', input), input.Length); ECC.PrivateKey := BobPrivateKey; aesKey := ecc.Decrypt(eccCipher); aes.Key := aesKey; Result := aes.Decrypt(aesCipher); end;
Pour les messages suivants, Alice et Bob peuvent enregistrer la clé aesKey et ne pas envoyer la chaîne eccCipher.
Syntaxe du code grâce à http://markup.su/highlighter/