public async void ConfigureSignalR() { // Client keys pair var client_x25519key = _dataEncryptor.CreateX25519EncryptorKey().Key; // Client public key bytes array var clientPublicKeyBytes = _dataEncryptor.GetX25519EncryptorPublicKeyBytes(client_x25519key); var token = GetToken(url); // SignalR hub url var stringUri = $"{url}/userNotification"; var options = new HttpConnectionOptions() { AccessTokenProvider = () => Task.FromResult(token), Url = new System.Uri(stringUri), }; var factory = new HttpConnectionFactory(Options.Create(options), new LoggerFactory()); hubConnection = new HubConnection(factory, new JsonHubProtocol(), null); hubConnection.On <string>("PublicKeyExchange", keyDTOstring => { // Server public key and nonce bytes var keyDto = JsonConvert.DeserializeObject <ServerPublicKeyDto>(keyDTOstring); ReadOnlySpan <byte> nonce = System.Convert.FromBase64String(keyDto.Nonce); // Create nonce from server nonce bytes clientEncryptorKey.Nonce = new NSec.Cryptography.Nonce(nonce.Slice(0, 4), nonce.Slice(4)); clientEncryptorKey.Key = _dataEncryptor.CreateAes256GcmSymmetricKey(System.Convert.FromBase64String(keyDto.PublicKey), client_x25519key); }); await hubConnection.StartAsync(); await hubConnection.InvokeAsync("PublicKeyExchange", System.Convert.ToBase64String(clientPublicKeyBytes)); }
public async void ConfigureSignalR() { // Client keys pair var client_x25519key = _dataEncryptor.CreateX25519EncryptorKey().Key; // Client public key bytes array var clientPublicKeyBytes = _dataEncryptor.GetX25519EncryptorPublicKeyBytes(client_x25519key); // SignalR hub url var stringUri = $"{url}/userRegistration"; var options = new HttpConnectionOptions() { Url = new System.Uri(stringUri), }; var factory = new HttpConnectionFactory(Options.Create(options), new LoggerFactory()); hubConnection = new HubConnection(factory, new JsonHubProtocol(), null); await hubConnection.StartAsync(); }