private void btnDo_Click(object sender, EventArgs e) { // 取邮箱地址 // 取邮箱用户名密码 // 取要拷贝的路径 AppConfig config = new AppConfig("ZSJob//App.config"); string OApop3Server = config.AppConfigGet("OApop3Server"); Int32 OApop3ServerPort = Convert.ToInt32(config.AppConfigGet("OApop3ServerPort")); string OAUsername = config.AppConfigGet("OAUsername"); string OAUserPwd = config.AppConfigGet("OAUserPwd"); string EmailSubject = config.AppConfigGet("EmailSubject"); string EmailAddress = config.AppConfigGet("EmailAddress"); // 加密 //string encryptPwd = EncodeHelper.Base64Encrypt(OAUserPwd); // 解密 string decryptPwd = EncodeHelper.Base64Decrypt(OAUserPwd); string OutPath = config.AppConfigGet("OutPath"); try { ReceiveMail(OApop3Server, OApop3ServerPort, OAUsername, decryptPwd, OutPath, EmailSubject, EmailAddress); } catch (Exception ex) { LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(AMSDownloadForm)); MessageDxUtil.ShowError(ex.Message); } }
private void btnEncrypt_Click(object sender, EventArgs e) { string original = "测试加密字符串"; Console.WriteLine("original:" + original); string encrypt = EncodeHelper.SHA256(original); Console.WriteLine("EncodeHelper.SHA256:" + encrypt); //DES加解密 encrypt = EncodeHelper.DesEncrypt(original); Console.WriteLine("EncodeHelper.DesEncrypt:" + encrypt); string decrypt = EncodeHelper.DesDecrypt(encrypt); Console.WriteLine("EncodeHelper.DesDecrypt:" + decrypt); //MD5加密 encrypt = EncodeHelper.MD5Encrypt(original); Console.WriteLine("EncodeHelper.MD5Encrypt:" + encrypt); encrypt = EncodeHelper.MD5EncryptHash(original); Console.WriteLine("EncodeHelper.MD5EncryptHash:" + encrypt); encrypt = EncodeHelper.MD5EncryptHashHex(original); Console.WriteLine("EncodeHelper.MD5EncryptHashHex:" + encrypt); encrypt = EncodeHelper.EncyptMD5_3_16(original); Console.WriteLine("EncodeHelper.EncyptMD5_3_16:" + encrypt); //Base64加解密 encrypt = EncodeHelper.Base64Encrypt(original); Console.WriteLine("EncodeHelper.Base64Encrypt:" + encrypt); decrypt = EncodeHelper.Base64Decrypt(encrypt); Console.WriteLine("EncodeHelper.Base64Encrypt:" + decrypt); encrypt = EncodeHelper.AES_Encrypt(original); Console.WriteLine("EncodeHelper.AES_Encrypt:" + encrypt); decrypt = EncodeHelper.AES_Decrypt(encrypt); Console.WriteLine("EncodeHelper.AES_Decrypt:" + decrypt); //MD5加密字符串然后检查是否被篡改 encrypt = MD5Util.GetMD5_32(original); bool flag = MD5Util.ValidateValue(encrypt); Console.WriteLine("flag: " + flag); //为文件增加MD5编码标签,然后验证是否被修改 string file = @"DB\test1.xls"; bool flag2 = MD5Util.AddMD5(file); Console.WriteLine("flag2: " + flag2); //对给定路径的文件进行验证,如果一致返回True,否则返回False bool flag3 = MD5Util.CheckMD5(file); Console.WriteLine("flag3: " + flag3); //生成加解密私钥、公钥 string publicKey = ""; string privateKey = ""; RSASecurityHelper.GenerateRSAKey(out privateKey, out publicKey); string originalString = "testdata"; string encryptedString = RSASecurityHelper.RSAEncrypt(publicKey, originalString); string originalString2 = RSASecurityHelper.RSADecrypt(privateKey, encryptedString); if (originalString == originalString2) { MessageDxUtil.ShowTips("解密完全正确"); } else { MessageDxUtil.ShowWarning("解密失败"); } string regcode = RSASecurityHelper.RSAEncrypSignature(privateKey, originalString); bool validated = RSASecurityHelper.Validate(originalString, regcode, publicKey); MessageDxUtil.ShowTips(validated ? "验证成功" : "验证失败"); }