static void Main(string[] args) { //load configuration data RemotingConfiguration.Configure(@"TestConsole.exe.config"); //(1). Test the data encryption/decryption using SAF.Cryptography // (a) test the symmatric cryptography string original = "This is a test!"; string encrypted = Encryption.Encrypt(original, "Profile1"); Console.WriteLine("Encrypted data is : " + encrypted); string decrypted = Decryption.Decrypt(encrypted, "Profile1"); Console.WriteLine("Decrypted data is : " + decrypted); // (b) test the asymmatric cryptography byte[] key; byte[] iv; byte[] signature; encrypted = Encryption.Encrypt(original, "Profile2", out key, out iv, out signature); Console.WriteLine("Encrypted data is : " + encrypted); decrypted = Decryption.Decrypt(encrypted, "Profile3", key, iv, signature); Console.WriteLine("Decrypted data is : " + decrypted); //(2). Test the secure remoting call via CryptoRemotingClient(Server)Sink. //Please refer to configuration file for profile information used for remoting calls. //creating the remoting object SampleBusiness sb = new SampleBusiness(); //invoking the secure remoting call. Console.WriteLine(sb.SayHelloWorld()); Console.WriteLine("press enter to exit"); Console.ReadLine(); }
public Command GetMessage() { string answer = sReader.ReadLine(); answer = Decryption.Decrypt(answer, MainInfo.key, MainInfo.iv); return(JsonConvert.DeserializeObject <Command>(answer)); }
public void Dispose() { _encryption = null; _decryption = null; _sha = null; _saltGenerator = null; }
public Object[] GetRegisterUsers(string FromDate, string ToDate) { DataSet ds = new DataSet(); string store = "Select * From Personal where CreateDate between @FromDate and @ToDate Order By CreateDate"; List <IDataParameter> parms = new List <IDataParameter>(); parms.Add(new SqlParameter("@FromDate", FromDate + " 00:00:00")); parms.Add(new SqlParameter("@ToDate", ToDate + " 23:59:59")); ds = Connection.GetDataSet(store, parms, CommandType.Text); //ds = Connection.GetDataSet(store); DataTable dt = ds.Tables[0]; var query = (from temp in dt.AsEnumerable() select new { //ID = temp.Field<Guid>("ID"), Data = Decryption.Decrypt(AppSettings.FormKey, temp.Field <String>("Data")), CreateDate = temp.Field <DateTime>("CreateDate").ToString("dd/MM/yyyy HH:mm:ss") }); return(query.ToArray()); }
public string uploadSharePointFile() { string result = "success"; try { string Username = Decryption.DecryptNew(System.Configuration.ConfigurationManager.AppSettings["UserName"].ToString()); string Password = Decryption.DecryptNew(System.Configuration.ConfigurationManager.AppSettings["Password"].ToString()); var destpath = Path.Combine(HttpContext.Current.Server.MapPath("~/CSV/CurrentFile"), "Global_IT_Roadmap.xlsx"); WebClient webClient = new WebClient(); webClient.Credentials = new NetworkCredential(Username, Password); webClient.OpenRead(SharepointPath); webClient.DownloadFile(SharepointPath, destpath); //var archivefileName = "Global_IT_Roadmap" + "_" + DateTime.Now.ToString("MMddyyhhmm"); //var archivepath = Path.Combine(HttpContext.Current.Server.MapPath("~/CSV/Archive"), archivefileName + ".xlsx"); //webClient.DownloadFile(SharepointPath, archivepath); return(result); } catch (Exception ex) { writeLog(ex); result = ex.ToString(); return(result); } }
private void btnDecrypt_Click_1(object sender, EventArgs e) { if (richTextBox1.Text == string.Empty) { MessageBox.Show("Please give a valid textfile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { stopwatch.Start(); Decryption decryption = new Decryption(); string encryptedmessage; encryptedmessage = decryption.GetBinary(richTextBox1.Text); richTextBox2.Lines = decryption.DecryptedMessage(encryptedmessage); message = richTextBox2.Text; string SetenceString = message; var result = string.Join(" ", SetenceString.Split(' ').Distinct()); richTextBox2.Text = result; stopwatch.Stop(); int duration = Convert.ToInt32(stopwatch.ElapsedMilliseconds); Communications com = new Communications(); Form1 form1 = new Form1(); int id = form1.GetUserID(); if (richTextBox2.Text == string.Empty) { MessageBox.Show("Please give a valid textfile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { com.AddCommunication(id, duration, message); } } }
public byte[] Decrypt() { byte[] encrypted_data = GetEncryptedSource(); if (encrypted_data.Length == 0) { Win32.Print("ERROR: Failed to detect encrypted data for method!"); return(new byte[0]); } Win32.Print("Encrypted: " + BitConverter.ToString(encrypted_data)); byte[] decrypted_data = new byte[0]; if (this.Encryption.Type == EncryptionType.aes) { decrypted_data = Decryption.DecryptAES(encrypted_data, GetDecryptionKey()); } else if (this.Encryption.Type == EncryptionType.xor) { decrypted_data = Decryption.DecrypteXOR(encrypted_data, 0x16); } else if (this.Encryption.Type == EncryptionType.rsa) { decrypted_data = Decryption.DecryptRSA(encrypted_data, new byte[0]); } return(decrypted_data); }
public void TestDecrypt() { byte[] bytesDecrypted = Decryption.Decrypt(this.BytesToDecrypt, 13u, this.Key, this.IV); string decryptedString = Encoding.ASCII.GetString(bytesDecrypted); Assert.AreEqual(decryptedString, this.Decrypted); }
private void decryptBtn_Click(object sender, EventArgs e) { if (decryptBox.ForeColor == SystemColors.InactiveCaption) { MessageBox.Show("No input!"); } else { try { string message = Decryption.GetMessage(Decryption.Decrypt(Decryption.DisplayArrayFromString(decryptBox.Text))); if (message != string.Empty) { outputBox.Text = message; } else { outputBox.Text = "Invalid Data"; } } catch (Exception) { outputBox.Text = "Data appears to be malformed or tampered."; } } }
public ActionResult Login(UserLoginModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var db = new MainDbContext()) { var emailCheck = db.Users.FirstOrDefault(u => u.Email == model.Email); var getPswd = db.Users.Where(u => u.Email == model.Email).Select(u => u.Password); var listPswd = getPswd.ToList(); var decryptPswd = (!listPswd.Any()) ? null : Decryption.Decrypt(getPswd.ToList()[0]); if (model.Email != null && model.Password == decryptPswd) { var getMail = db.Users.Where(u => u.Email == model.Email).Select(u => u.Email); var getName = db.Users.Where(u => u.Email == model.Email).Select(u => u.Username); var getCountry = db.Users.Where(u => u.Email == model.Email).Select(u => u.Country); var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, getName.ToList()[0]), new Claim(ClaimTypes.Email, getMail.ToList()[0]), new Claim(ClaimTypes.Country, getCountry.ToList()[0]) }, "ApplicationCookie"); Request.GetOwinContext().Authentication.SignIn(identity); return(RedirectToAction("Index", "Home")); } } ModelState.AddModelError("", "Invalid Email or Password"); return(View(model)); }
private X509Certificate2 GetCertificate(MessagingContext messagingContext) { Decryption decryption = messagingContext.ReceivingPMode.Security.Decryption; if (decryption.DecryptCertificateInformation == null) { throw new ConfigurationErrorsException( "Cannot start decrypting: no certificate information found " + $"in ReceivingPMode {messagingContext.ReceivingPMode.Id} to decrypt the message. " + "Please use either a <CertificateFindCriteria/> or <PrivateKeyCertificate/> to specify the certificate information"); } if (decryption.DecryptCertificateInformation is CertificateFindCriteria certFindCriteria) { return(_certificateRepository.GetCertificate( certFindCriteria.CertificateFindType, certFindCriteria.CertificateFindValue)); } if (decryption.DecryptCertificateInformation is PrivateKeyCertificate embeddedCertInfo) { return(new X509Certificate2( rawData: Convert.FromBase64String(embeddedCertInfo.Certificate), password: embeddedCertInfo.Password, keyStorageFlags: X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet)); } throw new NotSupportedException( "The decrypt-certificate information specified in the ReceivingPMode " + $"{messagingContext.ReceivingPMode.Id} could not be used to retrieve the certificate used for decryption. " + "Please use either a <CertificateFindCriteria/> or <PrivateKeyCertificate/> to specify the certificate information"); }
public void AesTest() { const string source = "2FYmJ9CZKwzGtYMNwkFD5yUbw2qh0ScoNJhSnCrULryaUoTGE+AB26mCt/6mAqE3"; const string str = "测试数据加密,123中英汇合acdefg"; var result = Decryption.Decrypt(source, "Aes"); Assert.AreEqual(str, result); }
public void DesTest() { const string source = "OGUYlWsRx5oLjgIR+OT0K1BG2V5wf3Rbg1ddANmhLEWDeQfUojIqig=="; const string str = "测试数据加密,中英汇合acdefg"; var result = Decryption.Decrypt(source, "DES"); Assert.AreEqual(str, result); }
public void RijndaelTest() { const string source = "Qfkfe201C/pmJTz/gyv3vGyaeYOnfKu1f1URRouCyWlzJjvpEGCeyX1JK2bln1NY"; const string str = "测试数据加密,中英汇合acdefg"; var result = Decryption.Decrypt(source, "Rijndael"); Assert.AreEqual(str, result); }
public void TripleDesTest() { const string source = "qCie0wIiEMo11VpoRMmrAd8zzqG0nyYII57V9sq4p1BEd1iELKAXSQ=="; const string str = "测试数据加密,中英汇合acdefg"; var result = Decryption.Decrypt(source, "TripleDES"); Assert.AreEqual(str, result); }
public void Rc2Test() { const string source = "eq0EPanGM6JSrfH5fvtzCsxUl9BxNpm78CXyFgks4J22wxzU8/Y3BA=="; const string str = "测试数据加密,中英汇合acdefg"; var result = Decryption.Decrypt(source, "RC2"); Assert.AreEqual(str, result); }
public void TestDecryptWithCompress() { byte[] bytesCompressed = Decryption.DecryptNoDecompress(this.BytesToDecrypt, 21u, this.Key, this.IV); byte[] bytesDecrypted = Decryption.Decompress(bytesCompressed, 13); string decryptedString = Encoding.ASCII.GetString(bytesDecrypted); Assert.AreEqual(decryptedString, this.Decrypted); }
public ActionResult EditUser(string userId) { var usId = Decryption.Decrypt(userId, true); var userDto = _iUserHelper.GetUserByUserId(Convert.ToInt32(usId)); userDto.UserTypesDtos = _iUserHelper.GetUserTypes(); return(View("EditUser", userDto)); }
public void HandleClient(object obj) { // retrieve client from parameter passed to thread TcpClient client = (TcpClient)obj; // sets two streams StreamWriter sWriter = new StreamWriter(client.GetStream(), Encoding.UTF8); StreamReader sReader = new StreamReader(client.GetStream(), Encoding.UTF8); Boolean bClientConnected = true; String sData = null; String respond = null; object lock_ = new object(); while (bClientConnected) { try { // reads from stream if (!client.Connected) { throw new Exception("Connection Close!"); } sData = sReader.ReadLine(); if (sData == null) { throw new Exception("Connection Close!"); } sData = Decryption.Decrypt(sData, Program.key, Program.iv); Command command = JsonConvert.DeserializeObject <Command>(sData); respond = Parser.Parse(command); Parser.RememberPlayer(command, respond, sWriter, lock_); if (respond == null) { // exit client bClientConnected = false; throw new Exception("Connection Close!"); } // to write something back. if (!respond.Equals("null")) { SendMessage(respond, sWriter, lock_); } } catch (Exception e) { sWriter.Close(); client.Close(); if (!e.Message.Equals("Connection Close!")) { Log.ErrorLog("Connection Error: " + e.Message); } Log.InfoLog("Client disconect..."); Console.WriteLine("Client disconect..."); return; } } }
public void DecryptLetters() { Decryption letters = new Decryption(); char[] key = "BCDFGH".ToCharArray(); string answer = letters.DecryptLetters(key); Assert.AreEqual("ABCEFG", answer); }
public void DecryptLetters3() { Decryption letters = new Decryption(); char[] key = "BCDEFGHIJKLMNOPQRSTUVWXYZA".ToCharArray(); string answer = letters.DecryptLetters(key); Assert.AreEqual("ABCDEFGHIJKLMNOPQRSTUVWXYZ", answer); }
public void DecryptNumbers2() { Decryption numbers = new Decryption(); char[] key = "3579".ToCharArray(); string answer = numbers.DecryptNumbers(key); Assert.AreEqual("2468", answer); }
public void DecryptNumbers3() { Decryption numbers = new Decryption(); char[] key = "23456789012345678900987654321".ToCharArray(); string answer = numbers.DecryptNumbers(key); Assert.AreEqual("12345678901234567899876543210", answer); }
public void DecryptMixed2() { Decryption mixed = new Decryption(); char[] key = "BCDEFGHGFEDCB".ToCharArray(); string answer = mixed.DecryptAlphaNumeric(key); Assert.AreEqual("ABCDEFGFEDCBA", answer); }
public void DecryptMixed3() { Decryption mixed = new Decryption(); char[] key = "3579XIPEPXFBQQSFDJBUF".ToCharArray(); string answer = mixed.DecryptAlphaNumeric(key); Assert.AreEqual("2468WHODOWEAPPRECIATE", answer); }
public void DecryptLetters2() { Decryption letters = new Decryption(); char[] key = "BFJPV".ToCharArray(); string answer = letters.DecryptLetters(key); Assert.AreEqual("AEIOU", answer); }
public async Task <string> Save([FromBody] RequestSaveQrInfoModel model) { int qId = Convert.ToInt32(Decryption.MXR(model.QrCode)); return (await Task.FromResult(_toolHistory.SaveQrCodeStatistical(qId, model.PhoneType, model.Ip, model.Province, model.EnterType, model.CilentCookie) ? "ok" : "no")); }
private void Decrypt_Click(object sender, EventArgs e) { if (CheckWhetherAllTheValuesAreValidOrnOt()) { if (Decryption.DecryptPGPData(InputFilePathValue.Text, outputfilepathValue.Text, password.Text, privatekeypath.Text)) { MessageBox.Show("Successfully Decrypted"); } } }
public void EncryptDecryptTest() { string key = Program.key; string iv = Program.iv; string data = "Hey Im Willi!"; string encrypt = Encryption.Encrypt(data, key, iv); string decrypt = Decryption.Decrypt(encrypt, key, iv); Assert.AreEqual(data, decrypt); }
private static string DAttack(BitArray plain, BitArray cipher, string key) { KeyGeneration keygen = new KeyGeneration(key); var decrypted = Decryption.Decrypt(cipher, keygen.K1, keygen.K2); if (Tools.BitArrayEquals(decrypted, plain)) { return(key); } return(null); }