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;
        }
Exemplo n.º 2
0
        public void TestPublicKeyExport()
        {
            RSAPublicKey pk = new RSAPrivateKey().PublicKey;
            string xml = pk.ToXml();

            RSAPublicKey copy = RSAPublicKey.FromXml(xml);
            Assert.AreEqual(xml, copy.ToXml());

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

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

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