public async Task <ActionResult> DeleteConfirmed(int id) { EncryptedItem encryptedItem = await db.EncryptedItems.FindAsync(id); db.EncryptedItems.Remove(encryptedItem); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "ID,Name,PublicKey,StorageLocation")] EncryptedItem encryptedItem) { if (ModelState.IsValid) { db.Entry(encryptedItem).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(encryptedItem)); }
public void TestHelperUnicode() { string testString = "普選正式選票2008年11月4日,星期二伊利諾州芝加哥市"; EncryptedItem item = EncryptionHelper.Encrypt( Encoding.Unicode.GetBytes(testString)); string result = Encoding.Unicode.GetString(EncryptionHelper.Decrypt(item)); Assert.AreNotEqual( testString, Encoding.Unicode.GetString(item.Data)); Assert.AreEqual(testString, result); }
public async Task <ActionResult> Create([Bind(Include = "Name,PublicKey,StorageLocation")] EncryptedItem encryptedItem) { if (ModelState.IsValid) { db.EncryptedItems.Add(encryptedItem); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(encryptedItem)); }
public void WrongDataDecrypt() { string result = string.Empty; string testString = "普選正式選票2008年11月4日,星期二伊利諾州芝加哥市"; EncryptedItem item = EncryptionHelper.Encrypt( Encoding.Unicode.GetBytes(testString)); byte[] data = new byte[item.Data.Length - 1]; Array.Copy( (Array)(item.Data), 1, (Array)data, 0, item.Data.Length - 1); item.Data = data; Encoding.Unicode.GetString(EncryptionHelper.Decrypt(item)); }
// GET: EncryptedItems/Delete/5 public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EncryptedItem encryptedItem = await db.EncryptedItems.FindAsync(id); if (encryptedItem == null) { return(HttpNotFound()); } return(View(encryptedItem)); }
/// <summary> /// Encrypts the specified string to Encrypt. /// </summary> /// <param name="bytesToEncrypt">The string to Encrypt.</param> /// <param name="shortKey">if set to <c>true</c> [short key].</param> /// <returns> /// A <see cref="EncryptedItem"/> containing details about /// the Encrypted string. /// </returns> /// <externalUnit cref="EncryptedItem"/> /// <externalUnit cref="SequoiaCryptoProvider"/> /// <revision revisor="dev01" date="1/28/2009" version="1.0.5.9"> /// Member Created /// </revision> public static EncryptedItem Encrypt( byte[] bytesToEncrypt, bool shortKey) { // create parm for return var encryptedItem = new EncryptedItem(); using (var crypto = new SequoiaCryptoProvider(shortKey)) { encryptedItem.Data = crypto.Encrypt( bytesToEncrypt); } return(encryptedItem); }
/// <summary> /// DeEncryptes the specified Encrypted item. /// </summary> /// <param name="encryptedItem">The Encrypted item.</param> /// <param name="shortKey">if set to <c>true</c> [short key].</param> /// <returns> /// The unencrypted value of the Encrypted data. /// </returns> /// <externalUnit cref="EncryptedItem"/> /// <externalUnit cref="SequoiaCryptoProvider"/> /// <revision revisor="dev01" date="1/28/2009" version="1.0.5.9"> /// Member Created /// </revision> public static byte[] Decrypt( EncryptedItem encryptedItem, bool shortKey) { // Review: should this be in Try/catch block? // Create return param byte[] results = null; using (var crypto = new SequoiaCryptoProvider(shortKey)) { results = crypto.Decrypt(encryptedItem.Data); } return(results); }
public void WrongDataHashTest() { byte[] encryptedData = null; string testString = "普選正式選票2008年11月4日,星期二伊利諾州芝加哥市"; string testPath = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\Encryption"); string publicKey = File.ReadAllText(Path.Combine(testPath, "PublicKey.xml")); var plainData = Encoding.Unicode.GetBytes(testString); var crypto = new SequoiaCryptoProvider(); var hasher = new SHA512Managed(); var hash = hasher.ComputeHash(plainData); // Change one byte of the hash plainData[0] = (byte)0; //Calculate the hash and append it to the data byte[] dataPlusHash = SequoiaCryptoProvider.AppendArrays( hash, plainData); // Symmetrically Encrypt data and hash with random key and IV byte[] encryptedDataPlusHash = crypto.SymmetricallyEncryptContent(dataPlusHash); // Create an Encrypted transport Key var transKey = new TransportKey(crypto); // Add transport Key to ecnrypted data encryptedData = SequoiaCryptoProvider.AppendArrays( transKey.GenerateTransportKey(publicKey), encryptedDataPlusHash); EncryptedItem item = new EncryptedItem(); item.Data = encryptedData; var result = EncryptionHelper.Decrypt(item, false); }
/// <summary> /// DeEncryptes the specified Encrypted item. /// </summary> /// <param name="encryptedItem">The Encrypted item.</param> /// <returns>The unEncrypted value of the Encrypted data.</returns> /// <externalUnit cref="EncryptedItem"/> /// <externalUnit cref="SequoiaCryptoProvider"/> /// <revision revisor="dev01" date="1/28/2009" version="1.0.5.9"> /// Member Created /// </revision> public static byte[] Decrypt(EncryptedItem encryptedItem) { return(EncryptionHelper.Decrypt(encryptedItem, true)); }
public void TestHelperEncrypteDecryptSerialize() { #region longstring for testing string testString = @" ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUV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QRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ "; #endregion int size = 0; EncryptedItem item = EncryptionHelper.Encrypt( Encoding.Unicode.GetBytes(testString)); size = item.EncryptedSize; string testPath = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\Encryption\TestingSerialize.enc"); File.WriteAllBytes( testPath, Encoding.Unicode.GetBytes(item.ToString())); byte[] encryptedFile = File.ReadAllBytes(testPath); EncryptedItem tmpItem = EncryptedItem.FromXml( Encoding.Unicode.GetString(encryptedFile)); Assert.AreEqual(size, tmpItem.EncryptedSize); string result = Encoding.Unicode.GetString(EncryptionHelper.Decrypt(item)); Assert.AreNotEqual( testString, Encoding.Unicode.GetString(item.Data)); Assert.AreEqual(testString, result); File.Delete(testPath); }