public IContentResponse HandlePasswordSet(NameValueCollection headers, Stream inputStream)
        {
            INameValueStore store = new RegistryStorage(Settings.RegistryPath);

            int contentLen = int.Parse(headers["Content-Length"]);

            if (contentLen == 0)
            {
                using (RSAPrivateKey _temporaryKey = new RSAPrivateKey(2048))
                {
                    store.Write("Transfers", "temp-key", Convert.ToBase64String(_temporaryKey.ToArray()));
                    return(new DynamicResponse("application/public-key", _temporaryKey.PublicKey.ToArray()));
                }
            }

            string tempkey;

            if (contentLen <= 2048 && store.Read("Transfers", "temp-key", out tempkey))
            {
                byte[] bytes = IOStream.Read(inputStream, contentLen);
                using (RSAPrivateKey _temporaryKey = RSAPrivateKey.FromBytes(Convert.FromBase64String(tempkey)))
                    bytes = _temporaryKey.Decrypt(bytes);

                _content.KeyPair.SetServerPassword(bytes);
            }
            return(DynamicResponse.Empty);
        }
Example #2
0
 public RSAKey(RSAPrivateKey privateKey)
     : this(privateKey.PublicKey)
 {
     _hasPrivateKey = true;
     _privateBits   = null;
     _privateKey    = privateKey;
     _privateHash   = Hash.SHA256(_privateKey.ToArray());
 }
Example #3
0
        public void TestPrivateKeyExport()
        {
            RSAPrivateKey pk  = new RSAPrivateKey();
            string        xml = pk.ToXml();

            RSAPrivateKey copy = RSAPrivateKey.FromXml(xml);

            Assert.AreEqual(xml, copy.ToXml());

            byte[] bytes = pk.ToArray();
            Assert.AreEqual(596, bytes.Length);

            copy = RSAPrivateKey.FromBytes(bytes);
            Assert.AreEqual(bytes, copy.ToArray());

            copy = RSAPrivateKey.FromParameters(pk.ExportParameters());
            Assert.AreEqual(bytes, copy.ToArray());
        }