コード例 #1
0
        private static async Task MainAsync(string[] args)
        {
            var serverCert = ServerCertificate?.Thumbprint;

            Console.WriteLine($"Server Certificate: {serverCert}");

            var client = new EnclaveClient(
                FindTestCertificate(),
                pinnedCertificates: new[] {
                new Certificate {
                    Thumbprint = serverCert
                }
            }
                );

            var key = await client.GenerateKey("rsa");

            var encryptedValue = await client.Encrypt(key, new { foo = "bar" });

            Console.WriteLine(encryptedValue.Value);

            ;

            var decrypted = await client.Decrypt <object>(key, encryptedValue.Value);

            Console.WriteLine(JsonConvert.SerializeObject(decrypted));

            ;

            var keys = await client.ListKeys();

            foreach (var k in keys)
            {
                Console.WriteLine(k.KeyId);
            }

            ;

            //var identity = await client.AuthenticateToken(KeyIdentifier.Parse("test"), "negotiate", RC4Ticket);

            ;

            var key2 = await client.GenerateKey("ecc");

            var signed = await client.Sign(key2, new { bar = "foo" });

            Console.WriteLine(signed);

            ;

            var signResult = await client.Validate(key2, signed);

            Console.WriteLine(signResult);

            ;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ebekker/Enclave.NET
        private static async Task MainAsync()
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("settings.json")
                                .AddEnvironmentVariables().Build();

            var server = configuration.GetSection("Server").Get <Server>();

            var client = new EnclaveClient(
                FindTestCertificate(server),
                pinnedCertificates: new[] {
                new Certificate {
                    Thumbprint = server.ServerCertificate.Thumbprint
                }
            }
                );

            var data = new { Protected = "super-secret-secret-stuff" };

            Console.WriteLine($"Data: " + JsonConvert.SerializeObject(data));

            var key = await client.GenerateKey("RSA");

            Console.WriteLine($"KeyId: {key.KeyId}");

            var encrypted = await client.Encrypt(key, data);

            Console.WriteLine($"Encrypted: {encrypted.Value}");

            var decrypted = await client.Decrypt <object>(key, encrypted.Value);

            Console.WriteLine($"Decrypted: {decrypted}");

            var signed = await client.Sign(key, data);

            Console.WriteLine($"Signed: {signed}");

            Console.ReadKey();
        }