cryptoapi

How to export a password-protected private key using MS CryptoAPI?

微笑、不失礼 提交于 2019-12-11 06:05:05
问题 Using Microsoft CryptoAPI, I've generated a new RSA key pair, and am now trying to export the private key to a PKCS#8 encrypted (password-protected) PEM file. I first investigated CryptExportPKCS8() and CryptExportPKCS8Ex(), but the former doesn't support encrypting the key, and the latter is not exported by crypt32.dll. MSDN says that both functions have been deprecated anyway. My current attempt is to pass a session key derived from the password to CryptExportKey(): HCRYPTPROV provider;

how to use Microsoft Crypto API with USB Dongle following PKCS#11

倖福魔咒の 提交于 2019-12-11 03:10:59
问题 I have safenet authentication usb token which was given by a company and they told me they have digital public key certificate inside. They gave me a password and a software by which i can see that it can detect certificate inside. Now i need to access this token's certificate and then i need to use signing , encryption and decryption using my development code. But the company didn't gave me any sdk so i have to do everything by C++ Microsoft CryptoAPI. I searched on google but i am not sure

Microsoft RSA CSP key size

坚强是说给别人听的谎言 提交于 2019-12-11 02:49:46
问题 From what I can see, Microsoft's RSA CSP always generates identical bitlength pseudo prime numbers. So if the key size is 1024, the P and Q values seem to be (?) guaranteed to be 512 bits each? Does anyone know for sure if this, in fact, is the case? I'm building an interoperability module between my own RSA implementation and Microsoft's. In my case I have built in a small random variance between P & Q values so for 1024 bit key I could end up with one value being 506 bits and the other 518.

Howto take a glimpse into mscorlib?

久未见 提交于 2019-12-11 02:00:44
问题 I want to read data into RSAParameters structure ( RSAParameters ) and did check twice, that the data is correct. But still, I get an error "invalid data" exception for this: bei System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr) bei System.Security.Cryptography.Utils._ImportKey(SafeProvHandle hCSP, Int32 keyNumber, CspProviderFlags flags, Object cspObject, SafeKeyHandle& hKey) bei System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters

Translating Win32 Crypto API calls to C# with System.Security.Cryptography

半城伤御伤魂 提交于 2019-12-10 13:14:52
问题 I have been given an assignment to drop one of our product's dll and replace it with a pure C# one. The old DLL is a .NET 2.0 Managed C++ (C++\CLI) which wraps calls to the Win32 native Crypto API. The new DLL should expose a new object with the same name & methods, but should be written with C# (.NET 4.0). Of course, the new DLL should encrypt that same way (and decrypt) as the old one - otherwise, all saved encrypted passwords in a persistent storage like in a DB or in a File - will not be

MD5 Crypto API returns incorrect hash for certain plaintexts

三世轮回 提交于 2019-12-10 11:58:10
问题 I'm attempting to use the Microsoft crypto APIs to compute an MD5 hash, but I'm getting incorrect hashes: #include <windows.h> #include <stdio.h> #include <wincrypt.h> char* HashMD5(char* data, DWORD *result) { DWORD dwStatus = 0; DWORD cbHash = 16; int i = 0; HCRYPTPROV cryptProv; HCRYPTHASH cryptHash; BYTE hash[16]; char *hex = "01234567879abcdef"; char *strHash = "00000000000000000000000000000000"; if(!CryptAcquireContext(&cryptProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))

WinHttp: How to use a temporary certificate store?

こ雲淡風輕ζ 提交于 2019-12-10 10:03:10
问题 I have a C++ application that makes a HTTPS connection to one of our servers. In my ideal world, I would like the following to occur: App Starts App makes Windows trust the server's root CA (no GUI please, just system calls) App talks to server, does its work, etc. App makes windows forget about the server's root CA done I do NOT want this root CA to necessarily be trusted by other apps. Therefore I don't want to install the cert system-wide. I also would like it if the user did not need

How to Sign an EXE with Additional Certificates using CryptoAPI and SignerSign

瘦欲@ 提交于 2019-12-09 21:45:10
问题 I'm trying to build a tool that will mass sign a bunch of files based on Kernel-Mode Code Signing requirements. I know that signtool can take an additional certificate for cross-signatures trust via the /ac argument, but have not been able to figure out how to do the same using SignerSign or SignerSignEx. I've even spied on signtool's API calls, and mirroring them does not seems to produce the same affect. Be aware, signtool or other command-line utilities cannot be used for this purpose due

How to extract public key from a .Net DLL in C#? [duplicate]

荒凉一梦 提交于 2019-12-08 13:44:46
问题 This question already has answers here : How do I read the public key from a signed C# exe (2 answers) Closed 4 years ago . I want to extract public key, not public key token, in C# from a autenticode signed .Net DLL? 回答1: To get a public key from an Autenticode signed .Net library use the following code: Assembly assembly = Assembly.LoadFrom("dll_file_name"); X509Certificate certificate = assembly.ManifestModule.GetSignerCertificate(); byte[] publicKey = certificate.GetPublicKey(); But this

BCryptImportKeyPair returns STATUS_INVALID_PARAMETER when i try to import public key

我怕爱的太早我们不能终老 提交于 2019-12-08 10:55:49
问题 I followed this example. I am trying to add the public key which i got from the server into the key Pair and I am getting STATUS_INVALID_PARAMETER. BCRYPT_DH_KEY_BLOB header; header.dwMagic = BCRYPT_DH_PUBLIC_MAGIC; header.cbKey = (ULONG)(pub_key.size()); cout << "header contents " << header.dwMagic << " : " << header.cbKey << endl; memcpy(&pubKeyBlobFromServer[0], &header, sizeof(BCRYPT_DH_KEY_BLOB)); // copy Public key cout << "size of pub_key " << pub_key.size() << endl; cout << "size of