private static void GeneratePublicKey()
        {
            var service = new AsymmetricEncryptionService();
            var pair    = service.GenerateKeyPairPem();

            Console.WriteLine(pair.Item2);
        }
        private static void TestEncription2()
        {
            var algo = new AsymmetricEncryptionService();

            var readerPrivate = new StreamReader("private-key-test.txt");
            var readerPublic  = new StreamReader("public-key-test.txt");

            var privateStr    = readerPrivate.ReadToEnd();
            var publicStrJson = readerPublic.ReadToEnd();

            var publicStr = JsonConvert.DeserializeObject <KeyJson>(publicStrJson).Key;

            var service = new SymmetricEncryptionService();
            var buf     = service.GenerateKey();

            var enc = algo.Encrypt(buf, publicStr);

            var str = Convert.ToBase64String(enc);

            Console.WriteLine(Convert.ToBase64String(buf));
            Console.WriteLine();
            Console.WriteLine(str);
            Console.WriteLine();

            enc = Convert.FromBase64String("ov0P6xO2AXxLJe7DgMmfjXjCPC488wAElzbTVy+N7/6Q4g0ld6iRnuXtI2FN06ym/loHSHH7sy9375xPoHy3bDp1jCcs1FrClnynlWUO5c2Xq5M1mQBYlcg3u5OG4wgttHtXa9/cftm1B9hl/Nh9ItSwKI/br61dlT+gebZzOO0=");

            algo = new AsymmetricEncryptionService();
            var res = algo.Decrypt(enc, privateStr);

            Console.WriteLine(Convert.ToBase64String(res));


            Console.ReadLine();
        }
Beispiel #3
0
 public CashoutCommandHandler(
     long brokerAccountId,
     IApiClient siriusApiClient,
     PrivateKeyService privateKeyService,
     ILogFactory logFactory,
     int notEnoughBalanceRetryDelayInSeconds)
 {
     _brokerAccountId   = brokerAccountId;
     _siriusApiClient   = siriusApiClient;
     _privateKeyService = privateKeyService;
     _notEnoughBalanceRetryDelayInSeconds = notEnoughBalanceRetryDelayInSeconds;
     _log = logFactory.CreateLog(this);
     _encryptionService = new AsymmetricEncryptionService();
 }
        private static void TestEncription()
        {
            var algo = new AsymmetricEncryptionService();

            var readerPrivate = new StreamReader("private-key-test.txt");
            var readerPublic  = new StreamReader("public-key-test.txt");

            var privateStr    = readerPrivate.ReadToEnd();
            var publicStrJson = readerPublic.ReadToEnd();

            var publicStr = JsonConvert.DeserializeObject <KeyJson>(publicStrJson).Key;

            var buf = Encoding.UTF8.GetBytes("Hello world!");

            var enc = algo.Encrypt(buf, publicStr);

            var str = Convert.ToBase64String(enc);

            Console.WriteLine();
            Console.WriteLine(str);
            Console.WriteLine();


            var res = algo.Decrypt(enc, privateStr);

            var txt = Encoding.UTF8.GetString(res);

            Console.WriteLine(txt);


            var s64 =
                "Y1hLuvDfQ4Dr71zIBYwcOPIfpzIMo+RWpgaY3A51s4xS1NeHcrWMCfMr4qq8d0mQbotx4g0UXu8Y4yTZSuYMeMW8ezjzGpbzV8aikk1Skc72OnmUuwt8/ns/HVQmMwYumn0VlKGiJMKiFOUHROUBC3D1bAv1L363qnu1Vmiifn8=";
            var d1 = Convert.FromBase64String(s64);

            res = algo.Decrypt(enc, privateStr);

            txt = Convert.ToBase64String(res);
            Console.WriteLine(txt);


            Console.ReadLine();
        }
Beispiel #5
0
        public override async Task <PingResponse> GetPing(PingRequest request, ServerCallContext context)
        {
            var validatorId = context.GetHttpContext().User.GetClaimOrDefault(Claims.KeyKeeperId);
            var publicKey   = context.GetHttpContext().User.GetClaimOrDefault(Claims.PublicKeyPem);

            if (string.IsNullOrEmpty(publicKey))
            {
                return(new PingResponse()
                {
                    Error = new ValidatorApiError()
                    {
                        Code = ValidatorApiError.Types.ErrorCodes.InternalServerError,
                        Message = "Incorrect Bearer Token."
                    }
                });
            }

            var message = _pingMessageReader.Get(PingMessageMyNoSqlEntity.GeneratePartitionKey(validatorId),
                                                 PingMessageMyNoSqlEntity.GenerateRowKey());

            var response = new PingResponse();

            if (message == null)
            {
                response.MessageEnc       = string.Empty;
                response.SignatureMessage = string.Empty;
            }
            else
            {
                var asynccrypto = new AsymmetricEncryptionService();
                var messageEnc  = asynccrypto.Encrypt(Encoding.UTF8.GetBytes(message.Message), publicKey);

                response.MessageEnc       = Convert.ToBase64String(messageEnc);
                response.SignatureMessage = "not-implemented-please-skip";

                await _pingMessageWriter.DeleteAsync(message.PartitionKey, message.RowKey);
            }

            _logger.LogInformation("GetPing response. ValidatorId='{ValidatorId}'; HasMessage={HasMessage}", validatorId, !string.IsNullOrEmpty(response.MessageEnc));

            return(response);
        }
        private static void TestSignature()
        {
            var readerPrivate = new StreamReader("private-key-test.txt");
            var readerPublic  = new StreamReader("public-key-test.txt");

            var privateStr = readerPrivate.ReadToEnd();
            var publicStr  = readerPublic.ReadToEnd();


            var data64 = "eyJUcmFuc2ZlckRldGFpbCI6eyJCbG9ja2NoYWluUHJvdG9jb2xJZCI6InByb3RvY29sLWlkIiwiT3BlcmF0aW9uSWQiOiJjNWY4OWE4NTI3MTE0N2M5YTBhYjFiYTZkY2FhZTVmYyIsIkJsb2NrY2hhaW5JZCI6IkV0aGVyZXVtIiwiTmV0d29ya1R5cGUiOiJ0ZXN0bmV0IiwiQXNzZXQiOnsiU3ltYm9sIjoiRVRIIiwiQXNzZXRBZGRyZXNzIjoiIiwiQXNzZXRJZCI6IiJ9LCJTb3VyY2UiOnsiQWRkcmVzcyI6ImZlNDM3ZWRiMTMyZDQ3YmE4ODdjMmM1ZWFjMzY5ZDRmIiwiQWRkcmVzc0dyb3VwIjoiQnJva2VyIEFjY291bnQgIzEiLCJOYW1lIjoiIiwiVGFnIjoiIiwiVGFnVHlwZSI6IiJ9LCJEZXN0aW5hdGlvbiI6eyJBZGRyZXNzIjoiMjU2NDI2NzJjZDdhNDQxMTk3M2ZkZTkxMjNiYTk1OWEiLCJBZGRyZXNzR3JvdXAiOiIiLCJOYW1lIjoiIiwiVGFnIjoiIiwiVGFnVHlwZSI6IiJ9LCJBbW91bnQiOiIxIiwiRmVlTGltaXQiOiIwLjAwMSIsIkNsaWVudENvbnRleHQiOnsiV2l0aGRyYXdhbFJlZmVyZW5jZUlkIjoiYWNjb3VudC03NDkyMTciLCJBY2NvdW50UmVmZXJlbmNlSWQiOiIxMjkxMSIsIlRpbWVzdGFtcCI6IjI4LjA5LjIwIDE0OjEzOjEwIiwiVXNlcklkIjoiIiwiQXBpS2V5SWQiOiJBcGkga2V5ICMzIiwiSVAiOiIxNzIuMTY0LjIwLjIifX0sIlJlc29sdXRpb24iOiJhcHByb3ZlIiwiUmVzb2x1dGlvbk1lc3NhZ2UiOiJhc2RmYXNkZiJ9";
            var data   = Convert.FromBase64String(data64);


            var sign = Convert.FromBase64String("Kf5iSGE44iSX+UMp7lz3bYaYHE5Rpwav/wztVJHQ2E6pjNYt/muXumL7I/dyzBpWkJIGsvnrkOGMB2LiRf+M30CCWKtlZ8U0upSGz1kvlwEDP8dbpo74wcByKQy9h73dJtCuVeFbxZ/PixVUUg3IfNKfM7uExhSIIlNa4AU38Hg=");

            var algo = new AsymmetricEncryptionService();

            var verfy = algo.VerifySignature(data, sign, publicStr);

            Console.WriteLine(verfy);

            Console.ReadLine();
        }
Beispiel #7
0
 public AsymmetricEncryptionServiceTests(ITestOutputHelper testOutputHelper)
 {
     _testOutputHelper = testOutputHelper;
     _service          = new AsymmetricEncryptionService();
 }