/// <summary> /// Decrypt and parses a JSON-encoded HandshakeToken. Also verifies that the /// token was encrypted by the ID that issued the token. /// </summary> /// <param name="encryptedHandshakeToken">The JSON-encoded SYNACK</param> /// <returns>The HandshakeToken object</returns> protected async Task <T> DecryptAndInstantiateHandshakeToken <T>(string encryptedHandshakeToken, ID id = null) where T : HandshakeToken, new() { string decryptedToken = _tokenCryptoService.Decrypt(encryptedHandshakeToken, _accountService.GetPrivateKeyAsByteArray()); HandshakeTokenFactory <T> handshakeTokenFactory = new HandshakeTokenFactory <T>(_idFacade, id); T handshakeToken = await handshakeTokenFactory.CreateHandshakeTokenAsync(decryptedToken); return(handshakeToken); }
private async Task ProcessCertificationConfirmationToken(string encryptedToken) { string decryptedToken = _tokenCryptoService.Decrypt(encryptedToken, _accountService.GetPrivateKeyAsByteArray()); CertificationConfirmationTokenFactory tokenFactory = new CertificationConfirmationTokenFactory(_certificateFacade); CertificationConfirmationToken token = await tokenFactory.CreateTokenAsync(decryptedToken); if (token.PublicKey != Ack.PublicKey) { throw new TokenPublicKeyMismatch(); } if (_tokenCryptoService.VerifySignature(token)) { await AddCertificatesToTheAccessibleAttributes(token.IssuedCertificates); } else { throw new SignatureDoesntMatchException("The signature was not " + "generated by the given " + "public Key"); } }