cryptoapi

How can I use a key blob generated from Win32 CryptoAPI in my .NET application?

I have an existing application that is written in C++ for Windows. This application uses the Win32 CryptoAPI to generate a TripleDES session key for encrypting/decrypting data. We're using the exponent of one trick to export the session key out as a blob, which allows the blob to be stored somewhere in a decrypted format. The question i...

I have P & G-- how do I use the Wincrypt API to generate a Diffie-Hellman keypair?

There's an MSDN article here, but I'm not getting very far: p = 139; g = 5; CRYPT_DATA_BLOB pblob; pblob.cbData = sizeof( ULONG ); pblob.pbData = ( LPBYTE ) &p; CRYPT_DATA_BLOB gblob; gblob.cbData = sizeof( ULONG ); gblob.pbData = ( LPBYTE ) &g; HCRYPTKEY hKey; if ( ::CryptGenKey( m_hCryptoProvider, CALG_DH_SF, CR...

I'm using Wincrypt for Diffie-Hellman-- can I export the shared secret in plain text?

OK-- thanks to Mike, I was able to get Wincrypt to generate a Diffie-Hellman keypair. I figured out out to export the public key, and how to import the other party's public key. According to the docs, upon import of the other party's public key, the shared secret has been computed. Great. I now need to get ahold of that shared secret...

How to encrypt small data block with only RSA public key using Microsoft ECSP?

I need to encrypt a small block of data (16 bytes) using 512 bit RSA public key -- quite an easy task for most cryptography libraries known to me, except for MS CSP API, as it seems. Documentation for CryptEncrypt function states that The Microsoft Enhanced Cryptographic Provider supports direct encryption with RSA public keys and de...

Is there a way to create a private key using CryptoAPI and seed it?

We have a need to create a private key that is seeded from 2 plaintext keys. The 2 plaintext keys are maintained by different managers. This is to satisfy a dual-control key requirements that we have. We can combine the two keys into a single seed. However, from reading the Microsoft CryptoAPI documentation, all key generation are comple...

Does Microsoft Provides a PKCS #11 provider that connects to its own MS CryptoAPI?

I'm looking to run some tests using the PKCS #11 interface and was wondering if Microsoft provided a software based implementation the provides PKCS #11 functionality? Rather then waiting for a HSM to arrive and be properly configured I'd rather get started on testing interaction with the interface now. ...

Java security - MSCAPI provider: How to use without password popup?

I've managed to use Sun's MSCAPI provider in my application. The problem I'm having now is that it always pops up a window, asking for a password, even though I've provided it in the code. This is a problem, because I need the cryptography functionality in a webservice. Here's the code I have now: String alias = "Alias to my PK"; char[...

P/Invoking CryptImportKey and marshaling structs

I'm trying to P/Invoke into CryptImportKey from C# to set a known key before encrypting data that will be decrypted in a C++ Win32 service at some point. I have the method signature for the P/Invoke and that all works fine but i can't get it to accept my key blob. The C++ structs are in comments below and my C# ones for marshaling are ...

Microsoft CryptoAPI Book

Hello :) I need to write my own SSL socket (CSocket ansestor) with server side certificate validation using Microsoft CryptoAPI. Can you tell me which book will help me (or any other user friendly source of information)? ...

Crypto API <-> .NET RSA interoperability

I have a unmanaged application that is generates an RC4 encryption key using Crypto API. This unmanaged application encrypts some data using this RC4 key. There is also a client side unmanaged application that uses this RC4 key to decrypt information. However, for this client app we're sending a session key -> the RC4 key encrytped usi...

Associate private key to certificate for PFXExportCertStoreEx

I'm trying to export certificate to pfx file. Here's what I do (simplified): h = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, CERT_STORE_CREATE_NEW_FLAG, NULL); p = CertCreateCertificateContext(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, CertBlob.pbData, CertBlob.cbData); CertSetCertificateContextProperty(p, CERT_KEY_P...

Hard coded AES-256 key with WinCrypt & CryptImportKey

I need to have a Win32 application load a hard coded AES-256 key, ideally using the WinCrypt.h methods. I've got my key in an unsigned char[32] but I can't find the correct format of a key blob to pass to CryptImportKey. Everything seems to give me invalid parameter errors. Is there any way to do this? (Also important is how to set IV i...

is cryptoapi good?

i'm writing a crypto program that does stuff like hashing (sha1), encryption, digital signatues for win32 in c++ is built in cryptoapi secure, or should i use some other library like crypto++ i need maximum security and works on all systems xp and vista (and optionally 2000), but at same time i need to minimize exe size and so don't want...

PKCS#10 request for a object key pair from PKCS#11

Hello There I have a RSA 1024 key pair generated using standard call from PKCS#11. I need to generate a PKCS#10 CSR for the public key. MS has the IEnroll4 dll which will allow to raise a CSR using createRequestWStr. The samples indicate that you need to generate a new key pair(a container with 2 objects in MS CAPI) and MS automatical...

CryptGetProvParam PP_ENUMCONTAINERS shows me only default certificate on smart card

I have Gemalto.NET Smart Card. I imported 2 certificates into it using Gemalto tools, which use sconnect (which as I suspect use Crypto API to do it when used in IE). When I run certutil -key -csp "Microsoft Base Smart Card Crypto Provider" I have following result Microsoft Base Smart Card Crypto Provider: 7c168bc3-dc1d-a627...

Load an X509 PEM file into Windows CryptoApi

Hi coders, I'm new to the whole Crypto thing, so I beg some basic pointers. I need to load .PEM (X509) "-----BEGIN RSA XXX KEY----- -----END RSA XXX KEY-----" into a Windows Crypto Api context to use with C++ (I found examples for Python and .NET but they use specific functions I can't relate to the plain Windows Crypto Api) I underst...

cryptoapi for dummies

Can some one point me to some books or online resources to help learn about the windows cryptoapi package? I did find "Cryptography for Visual Basic" by Richard Bondi. I'd be more interested in something aimed at C++ or the package in general. The MDSN is overwhelming! ...

Basic questions on Microsoft CryptoAPI

I've been looking through the MSDN trying to understand the crytoapi. Below are some questions and guesses as to how things might work. Any answers or confirmations or refuting of my surmises much appreciated. According to the note I found at http://msdn.microsoft.com/en-us/library/ms867086.aspx, the CSP keeps public private key pairs ...

Decryption with AES and CryptoAPI? When you know the KEY/SALT

Okay so i have a packed a proprietary binary format. That is basically a loose packing of several different raster datasets. Anyways in the past just reading this and unpacking was an easy task. But now in the next version the raster xml data is now to be encrypted using AES-256(Not my choice nor do we have a choice). Now we basically ...

Decrypting data files with wincrypt. Having trouble. Example shows CBase64Utils?

I need to decrypt some data files with wincrypt and examples are few and far between online. The most solid example I've found is here. However, this is using all sorts of types I cannot seem to find information about (CBase64Utils, CString, etc). I am reading the final solution, trying to understand the process, and have come to this...