Example #1
0
 private async Task Process(EncryptStringRequest args)
 {
     SendCommand(new EncryptStringDone()
     {
         StringToEncrypt = args.StringToEncrypt, EncryptedString = RsaSignatures.Encrypt(args.StringToEncrypt, args.ServerPubKey)
     });
 }
Example #2
0
        public void TestRsaSignatures()
        {
            var keys = RsaSignatures.GenerateKeys();

            Assert.AreNotEqual(keys.PrivKey, keys.PubKey);

            Assert.IsTrue(keys.PubKey.Length < keys.PrivKey.Length);

            var dataToSign = "some super secret data we need to sign";

            var signature = RsaSignatures.Sign(dataToSign, keys.PrivKey);


            var resultOk = RsaSignatures.VerifySignature(dataToSign, signature, keys.PubKey);

            Assert.AreEqual(true, resultOk);


            var resultFail = RsaSignatures.VerifySignature(dataToSign + "modify", signature, keys.PubKey);

            Assert.AreEqual(false, resultFail);


            var dataToEncrypt = "some super secret data we need to encrypt";

            var encrypted = RsaSignatures.Encrypt(dataToEncrypt, keys.PubKey);

            Assert.AreNotEqual(encrypted, dataToEncrypt);

            var decrypted = RsaSignatures.Decrypt(encrypted, keys.PrivKey);

            Assert.AreEqual(decrypted, dataToEncrypt);
        }