| Newsgroups |
gmane.comp.encryption.cryptlib |
| Message-ID |
<CAOq1pBF_vWSFE7g3crV7ySmLR_Damh+rTJTiEydXiSMF1wHQJA@mail.gmail.com> |
Hello!
Thank you for making CryptLib available. I see great potential with using it!
I have been trying to get started using public/private keys with not much luck.
What I want to do is the following:
* Imagine there are two people. A and B.
* I want A to generate a private/public key pair. B also generates a
public/private key pair.
* Then A sends its public key to B. B sends its public key to A.
* Now, A and B can send encrypted messages/files to each other by
using eachothers public keys.
So what I have done so far is this (error checking and so on ommitted):
1) create a keySet and generate a public/private key pair(?) adding it
to the keySet using:
cryptCreateContext( &keyContext, CRYPT_UNUSED, CRYPT_ALGO_RSA );
cryptSetAttributeString( keyContext, CRYPT_CTXINFO_LABEL,
name.c_str(), name.size());
cryptGenerateKey(keyContext);
cryptAddPrivateKey(cryptKeyset, keyContext, password.c_str());
3) load the public key from the keyset file (.p15):
cryptGetPublicKey(cryptKeyset, &publicKey, CRYPT_KEYID_NAME, name.c_str());
4) export the public key by, I guess wrapping it in a 3DES with no password:
cryptCreateContext(&cryptContext, CRYPT_UNUSED, CRYPT_ALGO_3DES);
cryptGenerateKey(cryptContext);
encryptedKey = malloc(encryptedKeyMaxLength);
cryptExportKey(encryptedKey, encryptedKeyMaxLength,
&encryptedKeyLength, publicKey, cryptContext);
5) Then I simulate that another user gets the encryptedKey.
6) The other users wants to import the key into keyContext(?):
cryptCreateContext(&cryptContext, CRYPT_UNUSED, CRYPT_ALGO_3DES);
//I guess for unwrapping 3DES without a password
cryptCreateContext(&keyContext, CRYPT_UNUSED, CRYPT_ALGO_RSA);
//Context to load public key into(?).
cryptImportKey(encryptedKey, encryptedKeyLength, keyContext,
cryptContext); //import encrypted key into keyContext
This last statement fails with error code CRYPT_ERROR_NOTINITED (-11).
I have been using the example on page 191 of the manual. It says in
the last comment that /* Party B imports the key using their private
key */. As you can see in
my example I have not yet created any private/public key pair in 6)
for the second user. And when I do that(generate a new privateKey into
keyContext) the cryptImportKey returns CRYPT_ERROR_WRONGKEY (-22).
So, does anynoe have any idea why this last statement fails?
Do I really create a public/private keypair using the code in 1) ?
Is there an easier way of doing this? Like a high level function? I
don't want to use external CA servers, just exchange public keys and
start sending encrypted messages/files.
Any help is greatly appreciated!
Best regards,
Mathias Anlér
_______________________________________________
Cryptlib mailing list
[email protected] via Mail: [email protected]
Archive: ftp://ftp.franken.de/pub/crypt/cryptlib/archives/
http://news.gmane.org/gmane.comp.encryption.cryptlib
Posts from non-subscribed addresses are blocked to prevent spam, please
subscribe in order to post messages.