mdc-2

cardmaker

Member
Joined
Jan 12, 2019
Messages
5
Programming Experience
Beginner
Hello, anyone can point me mdc2 hash function~in c#?
many thanks
 

Sheepings

Senior Programmer
Joined
Sep 5, 2018
Messages
466
Location
UK
Programming Experience
10+

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
461
Location
Virginia Beach, VA
Programming Experience
10+
Perhaps I didn't dig deep enough in that link (because of their poor UI design), but I only found the C implementation, but not the C# version that the OP was trying to find.
 

Sheepings

Senior Programmer
Joined
Sep 5, 2018
Messages
466
Location
UK
Programming Experience
10+

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
461
Location
Virginia Beach, VA
Programming Experience
10+
But those are language bindings that just call the C code that lives in the DLL.

I finally had a chance to download the CryptLib.zip file. Inside the zip file is all the C code, as well as various language bindings in the "bindings" directory. I found the "cryptlib.cs" and in the heart of that file was all these interop:
Code:
    [DllImport("cl32.dll", EntryPoint="cryptInit")]
    private static extern int wrapped_Init();
    [DllImport("cl32.dll", EntryPoint="cryptEnd")]
    private static extern int wrapped_End();
    [DllImport("cl32.dll", EntryPoint="cryptQueryCapability")]
    private static extern int wrapped_QueryCapability(int cryptAlgo, IntPtr cryptQueryInfo);
    [DllImport("cl32.dll", EntryPoint="cryptCreateContext")]
    private static extern int wrapped_CreateContext(IntPtr cryptContext, int cryptUser, int cryptAlgo);
    [DllImport("cl32.dll", EntryPoint="cryptDestroyContext")]
    private static extern int wrapped_DestroyContext(int cryptContext);
    [DllImport("cl32.dll", EntryPoint="cryptDestroyObject")]
    private static extern int wrapped_DestroyObject(int cryptObject);
    [DllImport("cl32.dll", EntryPoint="cryptGenerateKey")]
    private static extern int wrapped_GenerateKey(int cryptContext);
    [DllImport("cl32.dll", EntryPoint="cryptEncrypt")]
    private static extern int wrapped_Encrypt(int cryptContext, IntPtr buffer, int length);
    [DllImport("cl32.dll", EntryPoint="cryptDecrypt")]
    private static extern int wrapped_Decrypt(int cryptContext, IntPtr buffer, int length);
    [DllImport("cl32.dll", EntryPoint="cryptSetAttribute")]
    private static extern int wrapped_SetAttribute(int cryptHandle, int attributeType, int value);
    [DllImport("cl32.dll", EntryPoint="cryptSetAttributeString")]
    private static extern int wrapped_SetAttributeString(int cryptHandle, int attributeType, IntPtr value, int valueLength);
    [DllImport("cl32.dll", EntryPoint="cryptGetAttribute")]
    private static extern int wrapped_GetAttribute(int cryptHandle, int attributeType, IntPtr value);
    [DllImport("cl32.dll", EntryPoint="cryptGetAttributeString")]
    private static extern int wrapped_GetAttributeString(int cryptHandle, int attributeType, IntPtr value, IntPtr valueLength);
    [DllImport("cl32.dll", EntryPoint="cryptDeleteAttribute")]
    private static extern int wrapped_DeleteAttribute(int cryptHandle, int attributeType);
    [DllImport("cl32.dll", EntryPoint="cryptAddRandom")]
    private static extern int wrapped_AddRandom(IntPtr randomData, int randomDataLength);
    [DllImport("cl32.dll", EntryPoint="cryptQueryObject")]
    private static extern int wrapped_QueryObject(IntPtr objectData, int objectDataLength, IntPtr cryptObjectInfo);
    [DllImport("cl32.dll", EntryPoint="cryptExportKey")]
    private static extern int wrapped_ExportKey(IntPtr encryptedKey, int encryptedKeyMaxLength, IntPtr encryptedKeyLength, int exportKey, int sessionKeyContext);
    [DllImport("cl32.dll", EntryPoint="cryptExportKeyEx")]
    private static extern int wrapped_ExportKeyEx(IntPtr encryptedKey, int encryptedKeyMaxLength, IntPtr encryptedKeyLength, int formatType, int exportKey, int sessionKeyContext);
    [DllImport("cl32.dll", EntryPoint="cryptImportKey")]
    private static extern int wrapped_ImportKey(IntPtr encryptedKey, int encryptedKeyLength, int importKey, int sessionKeyContext);
    [DllImport("cl32.dll", EntryPoint="cryptImportKeyEx")]
    private static extern int wrapped_ImportKeyEx(IntPtr encryptedKey, int encryptedKeyLength, int importKey, int sessionKeyContext, IntPtr returnedContext);
    [DllImport("cl32.dll", EntryPoint="cryptCreateSignature")]
    private static extern int wrapped_CreateSignature(IntPtr signature, int signatureMaxLength, IntPtr signatureLength, int signContext, int hashContext);
    [DllImport("cl32.dll", EntryPoint="cryptCreateSignatureEx")]
    private static extern int wrapped_CreateSignatureEx(IntPtr signature, int signatureMaxLength, IntPtr signatureLength, int formatType, int signContext, int hashContext, int extraData);
    [DllImport("cl32.dll", EntryPoint="cryptCheckSignature")]
    private static extern int wrapped_CheckSignature(IntPtr signature, int signatureLength, int sigCheckKey, int hashContext);
    [DllImport("cl32.dll", EntryPoint="cryptCheckSignatureEx")]
    private static extern int wrapped_CheckSignatureEx(IntPtr signature, int signatureLength, int sigCheckKey, int hashContext, IntPtr extraData);
    [DllImport("cl32.dll", EntryPoint="cryptKeysetOpen")]
    private static extern int wrapped_KeysetOpen(IntPtr keyset, int cryptUser, int keysetType, IntPtr name, int options);
    [DllImport("cl32.dll", EntryPoint="cryptKeysetClose")]
    private static extern int wrapped_KeysetClose(int keyset);
    [DllImport("cl32.dll", EntryPoint="cryptGetPublicKey")]
    private static extern int wrapped_GetPublicKey(int keyset, IntPtr cryptContext, int keyIDtype, IntPtr keyID);
    [DllImport("cl32.dll", EntryPoint="cryptGetPrivateKey")]
    private static extern int wrapped_GetPrivateKey(int keyset, IntPtr cryptContext, int keyIDtype, IntPtr keyID, IntPtr password);
    [DllImport("cl32.dll", EntryPoint="cryptGetKey")]
    private static extern int wrapped_GetKey(int keyset, IntPtr cryptContext, int keyIDtype, IntPtr keyID, IntPtr password);
    [DllImport("cl32.dll", EntryPoint="cryptAddPublicKey")]
    private static extern int wrapped_AddPublicKey(int keyset, int certificate);
    [DllImport("cl32.dll", EntryPoint="cryptAddPrivateKey")]
    private static extern int wrapped_AddPrivateKey(int keyset, int cryptKey, IntPtr password);
    [DllImport("cl32.dll", EntryPoint="cryptDeleteKey")]
    private static extern int wrapped_DeleteKey(int keyset, int keyIDtype, IntPtr keyID);
    [DllImport("cl32.dll", EntryPoint="cryptCreateCert")]
    private static extern int wrapped_CreateCert(IntPtr certificate, int cryptUser, int certType);
    [DllImport("cl32.dll", EntryPoint="cryptDestroyCert")]
    private static extern int wrapped_DestroyCert(int certificate);
    [DllImport("cl32.dll", EntryPoint="cryptGetCertExtension")]
    private static extern int wrapped_GetCertExtension(int certificate, IntPtr oid, IntPtr criticalFlag, IntPtr extension, int extensionMaxLength, IntPtr extensionLength);
    [DllImport("cl32.dll", EntryPoint="cryptAddCertExtension")]
    private static extern int wrapped_AddCertExtension(int certificate, IntPtr oid, int criticalFlag, IntPtr extension, int extensionLength);
    [DllImport("cl32.dll", EntryPoint="cryptDeleteCertExtension")]
    private static extern int wrapped_DeleteCertExtension(int certificate, IntPtr oid);
    [DllImport("cl32.dll", EntryPoint="cryptSignCert")]
    private static extern int wrapped_SignCert(int certificate, int signContext);
    [DllImport("cl32.dll", EntryPoint="cryptCheckCert")]
    private static extern int wrapped_CheckCert(int certificate, int sigCheckKey);
    [DllImport("cl32.dll", EntryPoint="cryptImportCert")]
    private static extern int wrapped_ImportCert(IntPtr certObject, int certObjectLength, int cryptUser, IntPtr certificate);
    [DllImport("cl32.dll", EntryPoint="cryptExportCert")]
    private static extern int wrapped_ExportCert(IntPtr certObject, int certObjectMaxLength, IntPtr certObjectLength, int certFormatType, int certificate);
    [DllImport("cl32.dll", EntryPoint="cryptCAAddItem")]
    private static extern int wrapped_CAAddItem(int keyset, int certificate);
    [DllImport("cl32.dll", EntryPoint="cryptCAGetItem")]
    private static extern int wrapped_CAGetItem(int keyset, IntPtr certificate, int certType, int keyIDtype, IntPtr keyID);
    [DllImport("cl32.dll", EntryPoint="cryptCADeleteItem")]
    private static extern int wrapped_CADeleteItem(int keyset, int certType, int keyIDtype, IntPtr keyID);
    [DllImport("cl32.dll", EntryPoint="cryptCACertManagement")]
    private static extern int wrapped_CACertManagement(IntPtr certificate, int action, int keyset, int caKey, int certRequest);
    [DllImport("cl32.dll", EntryPoint="cryptCreateEnvelope")]
    private static extern int wrapped_CreateEnvelope(IntPtr envelope, int cryptUser, int formatType);
    [DllImport("cl32.dll", EntryPoint="cryptDestroyEnvelope")]
    private static extern int wrapped_DestroyEnvelope(int envelope);
    [DllImport("cl32.dll", EntryPoint="cryptCreateSession")]
    private static extern int wrapped_CreateSession(IntPtr session, int cryptUser, int formatType);
    [DllImport("cl32.dll", EntryPoint="cryptDestroySession")]
    private static extern int wrapped_DestroySession(int session);
    [DllImport("cl32.dll", EntryPoint="cryptPushData")]
    private static extern int wrapped_PushData(int envelope, IntPtr buffer, int length, IntPtr bytesCopied);
    [DllImport("cl32.dll", EntryPoint="cryptFlushData")]
    private static extern int wrapped_FlushData(int envelope);
    [DllImport("cl32.dll", EntryPoint="cryptPopData")]
    private static extern int wrapped_PopData(int envelope, IntPtr buffer, int length, IntPtr bytesCopied);
    [DllImport("cl32.dll", EntryPoint="cryptDeviceOpen")]
    private static extern int wrapped_DeviceOpen(IntPtr device, int cryptUser, int deviceType, IntPtr name);
    [DllImport("cl32.dll", EntryPoint="cryptDeviceClose")]
    private static extern int wrapped_DeviceClose(int device);
    [DllImport("cl32.dll", EntryPoint="cryptDeviceQueryCapability")]
    private static extern int wrapped_DeviceQueryCapability(int device, int cryptAlgo, IntPtr cryptQueryInfo);
    [DllImport("cl32.dll", EntryPoint="cryptDeviceCreateContext")]
    private static extern int wrapped_DeviceCreateContext(int device, IntPtr cryptContext, int cryptAlgo);
    [DllImport("cl32.dll", EntryPoint="cryptLogin")]
    private static extern int wrapped_Login(IntPtr user, IntPtr name, IntPtr password);
    [DllImport("cl32.dll", EntryPoint="cryptLogout")]
    private static extern int wrapped_Logout(int user);
 
Last edited:
Top Bottom