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; }
private void SaveSettings(string userId, string uri, string password) { INameValueStore storage = new RegistryStorage(); try { if (String.IsNullOrEmpty(password)) { storage.Delete(uri, "UserName"); storage.Delete(uri, "Password"); } else { storage.Write(uri, "UserName", userId); storage.Write(uri, "Password", Encryption.CurrentUser.Encrypt(password)); } } catch { } }