public Nonce ReserveNonce() { var nonce = _currentNonce.Increment(); Interlocked.Exchange(ref _currentNonce, nonce); Nonces.TryAdd(nonce.Value, nonce); return(nonce); }
public void EncryptWithADTestWithPlainText() { String key = "908b166535c01a935cf1e130a5fe895ab4e6f3ef8855d87e9b7581c4ab663ddc"; String additionalData = "90578e247e98674e661013da3c5c1ca6a8c8f48c90b485c0dfa1494e23d56d72"; String plaintext = "034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa"; String expectedCipherResult = "b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c3822"; Nonce nonce = new Nonce(); nonce.Increment(); (byte[] actualCipherText, byte[] mac) = ChaCha20Poly1305.EncryptWithAdditionalData(key.HexToByteArray(), nonce.GetBytes(), additionalData.HexToByteArray(), plaintext.HexToByteArray()); Assert.Equal(expectedCipherResult, actualCipherText.ToHex() + mac.ToHex()); }