Microsoft Capicom 2.1 On 64bit OS
第一步下载capicom.dll
https://files.cnblogs.com/files/chen110xi/DLL.7z
第二步注册capicom.dll至SysWow64
第三步VS中设置
1.添加com,capicom.dll的参考
2.COM 元件需注意是否內嵌 Interop 型別,设置为false(只有.NET 4.0+需要)
3.专案是否设置为x86
第四步开发
https://files.cnblogs.com/files/chen110xi/KeyC.7z
C#
/// <summary> /// 解密 /// </summary> /// <param name="EncryptMsg">需要解密的字串</param> /// <param name="DecryptKey">金鑰</param> /// <returns></returns> /// <remarks></remarks> public static string DoDecryptCommand(string EncryptMsg,string DecryptKey) { string strRetrun = string.Empty; // Dim Contents CAPICOM.EncryptedData EncryptedData = new CAPICOM.EncryptedData(); //dynamic EncryptedData = null; // Create the EncryptedData object. //EncryptedData = Interaction.CreateObject("CAPICOM.EncryptedData"); // Set decryption password. EncryptedData.SetSecret(DecryptKey); // Load the encrypted message. // LoadFile FileName, Message // Now decrypt it. EncryptedData.Decrypt(EncryptMsg); //DoDecryptCommand = EncryptedData.Content strRetrun = EncryptedData.Content; // Free resources. EncryptedData = null; return strRetrun; } // End DoDecryptCommand /// <summary> /// 加密 /// </summary> /// <param name="Content">要加密的字串</param> /// <param name="Algorithm">預設3</param> /// <param name="KeyLength">預設0</param> /// <param name="Password">金鑰</param> /// <returns></returns> /// <remarks></remarks> public static string DoEncryptCommand(string Content, CAPICOM.CAPICOM_ENCRYPTION_ALGORITHM Algorithm, CAPICOM.CAPICOM_ENCRYPTION_KEY_LENGTH KeyLength, string Password) { string functionReturnValue = ""; CAPICOM.EncryptedData EncryptedData = new CAPICOM.EncryptedData(); // Set algorithm, key size, and encryption password. EncryptedData.Algorithm.Name = Algorithm; EncryptedData.Algorithm.KeyLength = KeyLength; EncryptedData.SetSecret(Password); // Now encrypt it. EncryptedData.Content = Content; functionReturnValue = EncryptedData.Encrypt(); // Free resources. EncryptedData = null; return functionReturnValue; }
VB
Imports CAPICOM Module Decrypt 'Public Fire_Up, Login_OK, Pass1 As String ''' <summary> ''' 解密 ''' </summary> ''' <param name="EncryptMsg">密文</param> ''' <param name="DecryptKey">密匙</param> ''' <returns>明文</returns> ''' <remarks></remarks> Public Function DoDecryptCommand(ByVal EncryptMsg, ByVal DecryptKey, Optional ByVal Algorithm = 0, Optional ByVal KeyLength = 0) 'Dim Contents 'Dim EncryptedData '' Create the EncryptedData object. 'EncryptedData = CreateObject("CAPICOM.EncryptedData") '' Set decryption password. 'EncryptedData.Algorithm.Name = Algorithm 'EncryptedData.Algorithm.KeyLength = KeyLength 'EncryptedData.SetSecret(DecryptKey) '' Load the encrypted message. '' LoadFile FileName, Message '' Now decrypt it. 'EncryptedData.Decrypt(EncryptMsg) 'Nelson Mark 'Contents = Trim(EncryptedData.Content) 'Nelson Mark 'Pass1 = Contents 'EncryptedData = Nothing 'Return Contents 'Nelson Mark Dim encryptedData As New CAPICOM.EncryptedData encryptedData.Algorithm.Name = 0 encryptedData.Algorithm.KeyLength = 0 encryptedData.SetSecret(DecryptKey, CAPICOM_SECRET_TYPE.CAPICOM_SECRET_PASSWORD) encryptedData.Decrypt(EncryptMsg) Return encryptedData.Content End Function 'Const CAPICOM_ENCRYPTION_ALGORITHM_RC2 = 0 'Const CAPICOM_ENCRYPTION_ALGORITHM_RC4 = 1 'Const CAPICOM_ENCRYPTION_ALGORITHM_DES = 2 'Const CAPICOM_ENCRYPTION_ALGORITHM_3DES = 3 'Const CAPICOM_ENCRYPTION_ALGORITHM_AES = 4 'Const CAPICOM_ENCRYPTION_KEY_LENGTH_MAXIMUM = 0 'Const CAPICOM_ENCRYPTION_KEY_LENGTH_40_BITS = 1 'Const CAPICOM_ENCRYPTION_KEY_LENGTH_56_BITS = 2 'Const CAPICOM_ENCRYPTION_KEY_LENGTH_128_BITS = 3 'Const CAPICOM_ENCRYPTION_KEY_LENGTH_192_BITS = 4 'Const CAPICOM_ENCRYPTION_KEY_LENGTH_256_BITS = 5 ''' <summary> ''' 加密 ''' </summary> ''' <param name="Content">明文</param> ''' <param name="DecryptKey">密匙</param> ''' <param name="Algorithm">加密類型:0:RSA RC2;1:RSA RC4;2:DES;3:3DES</param> ''' <param name="KeyLength">密匙長度:0:CAPICOM_KEY_LENGTH_MAXIMUM;1:CAPICOM_KEY_LENGTH_40_BITS(40-bit);2:56-bit;3:128-bit;5:256;</param> ''' <returns>密文</returns> ''' <remarks></remarks> Function DoEncryptCommand(ByVal Content, ByVal DecryptKey, Optional ByVal Algorithm = 0, Optional ByVal KeyLength = 0) 'Dim EncryptedData '' Create the EncryptedData object. 'EncryptedData = CreateObject("CAPICOM.EncryptedData") '' Set algorithm, key size, and encryption password. 'EncryptedData.Algorithm.Name = Algorithm 'EncryptedData.Algorithm.KeyLength = KeyLength 'EncryptedData.SetSecret(DecryptKey) '' Now encrypt it. 'EncryptedData.Content = Content 'DoEncryptCommand = EncryptedData.Encrypt '' Free resources. 'EncryptedData = Nothing Dim encryptedData = New EncryptedDataClass() encryptedData.Content = Content encryptedData.Algorithm.Name = 0 encryptedData.Algorithm.KeyLength = 0 encryptedData.SetSecret(DecryptKey, CAPICOM_SECRET_TYPE.CAPICOM_SECRET_PASSWORD) Return encryptedData.Encrypt(CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64) 'Dim functionReturnValue = "" 'Dim EncryptedData = New CAPICOM.EncryptedData() 'EncryptedData.Algorithm.Name = Algorithm 'EncryptedData.Algorithm.KeyLength = KeyLength 'EncryptedData.SetSecret(DecryptKey) 'EncryptedData.Content = Content 'functionReturnValue = EncryptedData.Encrypt() 'Return functionReturnValue End Function ' End DoEncryptCommand End Module
分类:
c#
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架