/// <summary> /// Decrypts some data with the Windows Hello API from a file. /// </summary> public static void Main() { Console.WriteLine("Starting"); var handle = new IntPtr(); var provider = WinHelloProvider.CreateInstance("Hello", handle); provider.SetPersistentKeyName("Test"); var parentPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent?.Parent?.FullName; if (parentPath == null) { Console.WriteLine("Some error occurred with the parent path..."); return; } var path = Path.Combine(parentPath, "test.dat"); var encryptedData = File.ReadAllBytes(path); var decryptedData = provider.PromptToDecrypt(encryptedData); Console.WriteLine($"Decrypted data: { BitConverter.ToString(decryptedData).Replace("-", " ")}"); Console.WriteLine("Done."); Console.ReadKey(); }
/// <summary> /// Encrypts some data with the Windows Hello API and writes the encrypted data to a file. /// </summary> public static void Main() { Console.WriteLine("Starting."); var handle = new IntPtr(); string dataToEncrypt = "This is the text we want to check"; byte[] data = Encoding.ASCII.GetBytes(dataToEncrypt); Console.WriteLine("Decrypted data: " + dataToEncrypt); IAuthProvider provider = new WinHelloProvider("Hello", handle); var encryptedData = provider.Encrypt(data); Console.WriteLine($"Encrypted data: { BitConverter.ToString(encryptedData).Replace("-", " ")}"); var parentPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent?.Parent?.FullName; if (parentPath == null) { Console.WriteLine("Some error occurred with the parent path..."); } var path = Path.Combine(parentPath, "test.dat"); File.WriteAllBytes(path, encryptedData); Console.WriteLine("Done."); Console.ReadKey(); }
public void WindowsHelloTest() { var handle = new IntPtr(); var data = new byte[] { 0x32, 0x32 }; IAuthProvider provider = new WinHelloProvider("Hello", handle); var encryptedData = provider.Encrypt(data); var decryptedData = provider.PromptToDecrypt(encryptedData); CollectionAssert.AreEqual(data, decryptedData); }
public void WindowsHelloTest() { var handle = new IntPtr(); const string Message = "Windows Hello Test"; var data = new byte[] { 0x32, 0x32 }; Console.WriteLine(BitConverter.ToString(data)); var provider = WinHelloProvider.CreateInstance(Message, handle); Console.WriteLine("Instance created."); var encryptedData = provider.Encrypt(data); Console.WriteLine("Encrypted data:"); Console.WriteLine(BitConverter.ToString(encryptedData)); var decryptedData = provider.PromptToDecrypt(encryptedData); Console.WriteLine("Decrypted data:"); Console.WriteLine(BitConverter.ToString(decryptedData)); CollectionAssert.AreEqual(data, decryptedData); }
/// <summary> /// Encrypts some data with the Windows Hello API and writes the encrypted data to a file. /// </summary> // ReSharper disable once UnusedMember.Global public static void Main() { Console.WriteLine("Starting."); var handle = new IntPtr(); var data = new byte[] { 0x32, 0x32 }; Console.WriteLine($"Decrypted data: { BitConverter.ToString(data).Replace("-", " ")}"); var provider = WinHelloProvider.CreateInstance("Hello", handle); provider.SetPersistentKeyName("Test"); var encryptedData = provider.Encrypt(data); Console.WriteLine($"Encrypted data: { BitConverter.ToString(encryptedData).Replace("-", " ")}"); var parentPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent?.Parent?.FullName; if (parentPath == null) { Console.WriteLine("Some error occurred with the parent path..."); } }
/// <summary> /// Decrypts some data with the Windows Hello API from a file. /// </summary> public static void Main() { Console.WriteLine("Starting"); var handle = new IntPtr(); WinHelloProvider provider = new WinHelloProvider("Hello", handle); var parentPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent?.Parent?.FullName; if (parentPath == null) { Console.WriteLine("Some error occurred with the parent path..."); } var path = Path.Combine(parentPath, "test.dat"); var encryptedData = File.ReadAllBytes(path); //var decryptedData = provider.PromptToDecrypt(encryptedData); var ChkResult = WinHelloProvider.NCryptOpenStorageProvider(out var ngcProviderHandle, "Microsoft Passport Key Storage Provider", 0); ChkResult = WinHelloProvider.NCryptOpenKey( ngcProviderHandle, out var ngcKeyHandle, WinHelloProvider.CurrentPassportKeyName.Value, 0, CngKeyOpenOptions.None); var decryptedData = new byte[encryptedData.Length * 2]; var integ = WinHelloProvider.NCryptDecrypt(ngcKeyHandle, encryptedData, encryptedData.Length, IntPtr.Zero, decryptedData, decryptedData.Length, out var pcbResult, WinHelloProvider.NcryptPadPkcs1Flag); Array.Resize(ref decryptedData, pcbResult); string decryptedString = Encoding.ASCII.GetString(decryptedData); Console.WriteLine("Decrypted data: " + decryptedString); Console.WriteLine("Done."); Console.ReadKey(); }