static async Task Main(string[] args) { // Import parameters for the elliptic curve prime256v1 var ecParameters = CustomNamedCurves.GetByOid(X9ObjectIdentifiers.Prime256v1); var publicKeyStore = new InMemoryPublicKeyStore(); var publicKey = await publicKeyStore.GetAsync(); _initiator = new Initiator(); // 1. Initiate communication with a masked point P = r*T = r*Hash(t) var init = _initiator.Initiate(ecParameters.Curve); var t = init.t; var r = init.r; var P = init.P; // 2. Generate token Q = k*P and proof (c,z) of correctness var(Q, proofC, proofZ) = await _tokenApiClient.GenerateTokenAsync(ecParameters.Curve, P); // 3. Randomise the token Q, by removing the mask r: W = (1/r)*Q = k*T. Also checks that proof (c,z) is correct. var W = _initiator.RandomiseToken(ecParameters, publicKey.Q, P, Q, proofC, proofZ, r); // 4. Verify that the token (t,W) is correct. var isVerified = await _tokenApiClient.VerifyTokenAsync(t, W); if (isVerified) { Console.WriteLine("Token is valid."); } else { Console.WriteLine("Token is invalid."); Debug.Fail("Token is invalid."); } }
private void SetupWithInMemoryKeyStores() { var publicKeyStore = new InMemoryPublicKeyStore(); _publicKey = publicKeyStore.GetAsync().GetAwaiter().GetResult(); var privateKeyStore = new InMemoryPrivateKeyStore(); _privateKey = privateKeyStore.GetAsync().GetAwaiter().GetResult(); }
public ProtocolTests() { // Import parameters for the elliptic curve prime256v1 _ecParameters = CustomNamedCurves.GetByOid(X9ObjectIdentifiers.Prime256v1); var publicKeyStore = new InMemoryPublicKeyStore(); _publicKey = publicKeyStore.GetAsync().GetAwaiter().GetResult(); var privateKeyStore = new InMemoryPrivateKeyStore(); _privateKey = privateKeyStore.GetAsync().GetAwaiter().GetResult(); _wrongPrivateKey = _privateKey.Add(BigInteger.One); _initiator = new Initiator(); _tokenGenerator = new TokenGenerator(); _tokenVerifier = new TokenVerifier(new InMemorySeedStore()); }