支付相关-算法知识2
参考资料:Enveloped and Signed CMS/PKCS #7 Message
资料地址:https://docs.microsoft.com/en-us/previous-versions/bb885086(v=vs.90)?redirectedfrom=MSDN
参考资料:
资料地址:
project:aspose-pdf/Aspose.Pdf-for-.NET
File name: Examples/CSharp/AsposePDF/DigitallySign.cs
using System.IO; using System; using Aspose.Pdf; using Aspose.Pdf.Facades; using System.Collections; using Aspose.Pdf.Forms; namespace Aspose.Pdf.Examples.CSharp.AsposePDF.SecuritySignatures { public class DigitallySign { public static void Run() { try { // ExStart:DigitallySign // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures(); string pbxFile = ""; string inFile = dataDir + @"DigitallySign.pdf"; string outFile = dataDir + @"DigitallySign_out.pdf"; using (Document document = new Document(inFile)) { using (PdfFileSignature signature = new PdfFileSignature(document)) { PKCS7 pkcs = new PKCS7(pbxFile, "WebSales"); // Use PKCS7/PKCS7Detached objects DocMDPSignature docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100); // Set signature appearance signature.SignatureAppearance = dataDir + @"aspose-logo.jpg"; // Create any of the three signature types signature.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature); // Save output PDF file signature.Save(outFile); } } using (Document document = new Document(outFile)) { using (PdfFileSignature signature = new PdfFileSignature(document)) { IList sigNames = signature.GetSignNames(); if (sigNames.Count > 0) // Any signatures? { if (signature.VerifySigned(sigNames[0] as string)) // Verify first one { if (signature.IsCertified) // Certified? { if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission { // Do something } } } } } } // ExEnd:DigitallySign } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }
----------------------------------------------------------------
参考资料:Encrypt and Decrypt Data with C#
资料地址:https://www.codeproject.com/articles/14151/encrypt-and-decrypt-data-with-csharp-2
public static string Encrypt(string toEncrypt, bool useHashing) { byte[] keyArray; byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt); System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader(); // Get the key from config file string key = (string)settingsReader.GetValue("SecurityKey", typeof(String)); //System.Windows.Forms.MessageBox.Show(key); //If hashing use get hashcode regards to your key if (useHashing) { MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider(); keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key)); //Always release the resources and flush data //of the Cryptographic service provide. Best Practice hashmd5.Clear(); } else keyArray = UTF8Encoding.UTF8.GetBytes(key); TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider(); //set the secret key for the tripleDES algorithm tdes.Key = keyArray; //mode of operation. there are other 4 modes. We choose ECB(Electronic code Book) tdes.Mode = CipherMode.ECB; //padding mode(if any extra byte added) tdes.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = tdes.CreateEncryptor(); //transform the specified region of bytes array to resultArray byte[] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); //Release resources held by TripleDes Encryptor tdes.Clear(); //Return the encrypted data into unreadable string format return Convert.ToBase64String(resultArray, 0, resultArray.Length); }
public static string Decrypt(string cipherString, bool useHashing) { byte[] keyArray; //get the byte code of the string byte[] toEncryptArray = Convert.FromBase64String(cipherString); System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader(); //Get your key from config file to open the lock! string key = (string)settingsReader.GetValue("SecurityKey", typeof(String)); if (useHashing) { //if hashing was used get the hash code with regards to your key MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider(); keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key)); //release any resource held by the MD5CryptoServiceProvider hashmd5.Clear(); } else { //if hashing was not implemented get the byte code of the key keyArray = UTF8Encoding.UTF8.GetBytes(key); } TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider(); //set the secret key for the tripleDES algorithm tdes.Key = keyArray; //mode of operation. there are other 4 modes. //We choose ECB(Electronic code Book) tdes.Mode = CipherMode.ECB; //padding mode(if any extra byte added) tdes.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = tdes.CreateDecryptor(); byte[] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); //Release resources held by TripleDes Encryptor tdes.Clear(); //return the Clear decrypted TEXT return UTF8Encoding.UTF8.GetString(resultArray); }
-------------------------------------------------------------------------------
参考资料:https://www.c-sharpcorner.com/UploadFile/f8fa6c/data-encryption-and-decryption-in-C-Sharp/
资料地址:Data Encryption And Decryption in C#
using System; using System.Security.Cryptography; using System.Text; namespace DataEncrypterDecrypter { public class CryptoEngine { public static string Encrypt(string input, string key) { byte[] inputArray = UTF8Encoding.UTF8.GetBytes(input); TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider(); tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key); tripleDES.Mode = CipherMode.ECB; tripleDES.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = tripleDES.CreateEncryptor(); byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length); tripleDES.Clear(); return Convert.ToBase64String(resultArray, 0, resultArray.Length); } public static string Decrypt(string input, string key) { byte[] inputArray = Convert.FromBase64String(input); TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider(); tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key); tripleDES.Mode = CipherMode.ECB; tripleDES.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = tripleDES.CreateDecryptor(); byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length); tripleDES.Clear(); return UTF8Encoding.UTF8.GetString(resultArray); } } }
关键词:Decrypting PKCS#7 encrypted data in C#
地址:https://stackoverflow.com/questions/1503974/decrypting-pkcs7-encrypted-data-in-c-sharp
地址:https://csharp.hotexamples.com/examples/iTextSharp.text.pdf/PdfPKCS7/-/php-pdfpkcs7-class-examples.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
2018-11-29 iis托管管道模式-学习
2018-11-29 https单向证书
2018-11-29 单例模式再学习
2018-11-29 sql经常出现死锁解决办法
2018-11-29 sqlserver结束和监视耗时的sql