public ActionResult Create(string passphrase = null, string publickey = null, string privatekey = null, string privatekeyhash = null, DateTime?releasedate = null) { if (string.IsNullOrWhiteSpace(passphrase) && string.IsNullOrWhiteSpace(publickey)) { Response.StatusCode = 400; // Response.Status = "MissingPassphraseOrPublicKey"; return(SerializeResult("Either a passphrase or a publickey parameter is required")); } if (!string.IsNullOrWhiteSpace(publickey) && string.IsNullOrWhiteSpace(privatekey)) { Response.StatusCode = 400; return(SerializeResult("When sneding the public key, you must also send the privatekeyhash")); } CryptoKey key = !string.IsNullOrWhiteSpace(passphrase) ? CryptoKey.CreateRequestWithPassPhrase(passphrase) : CryptoKey.CreateRequestWithPublicKey(publickey, privatekey, true, privatekeyhash); if (releasedate != null) { key.ReleaseDate = (DateTime)releasedate; } requestRepository.AddRequest(key); return(SerializeResult(key)); }
public void Can_CreateRequestWithPublicKey_AndRetrieveKeys() { var repository = new RequestRepository(); var keys = AsymmetricCryptoProvider.GenerateKeys(); keys.PrivateKey = new SymmetricCryptoProvider().EncryptWithKey(keys.PrivateKey, password); var request = CryptoKey.CreateRequestWithPublicKey(keys.PublicKey, keys.PrivateKey, true); repository.AddRequest(request); repository.AttachMessageToRequest(request.KeyToken, message); var retrieved = repository.GetRequest(request.KeyToken); var msg = repository.GetDecryptedMessagesWithPassphrase(request.KeyToken, password); Assert.IsTrue(request.IsPrivateKeyEncrypted); Assert.IsTrue(request.KeyToken == retrieved.KeyToken); Assert.IsTrue(msg.First().MessageData == message); }