|
-
March 11th, 2002, 11:20 AM
#1
Who made RSA?
I'm building RSA, but not use MSDN lib.
Where can I load agorithm of RSA?
Ex : big integer, test prime...
Thank very much.
-
March 11th, 2002, 04:05 PM
#2
Re: Who made RSA?
Email me at [email protected] if you want some RSA implementation code.
Any one who knows he/she is not smart is smart.
Any one who knows he/she is smart is not smart.
You ask me if I am smart or not? Well...
I don't know - you tell me :-)
-
March 11th, 2002, 04:26 PM
#3
Re: Who made RSA?
RSA Security had the patent until September 6, 2000 (it's now free).
The RSA algorithm was invented by Ronald L. Rivest, Adi Shamir, and Leonard Adleman in 1977.
The algorithm is described in the PKCS #1 document, see http://www.rsasecurity.com/rsalabs/p...s-1/index.html.
***
I like feedback, so please rate my answer.
-
March 11th, 2002, 09:48 PM
#4
-
September 29th, 2008, 03:00 AM
#5
Re: Who made RSA?
do u have an SHA-256/RSA implementation on C/C++?
-
September 29th, 2008, 03:01 AM
#6
Re: Who made RSA?
do u have an SHA-256/RSA implementation on C/C++?
Edit/Delete Message
-
September 29th, 2008, 05:48 AM
#7
Re: Who made RSA?
You could try the CryptoAPI from Microsoft. Or the Crypto++ library. Or this: http://www.codeproject.com/KB/cpp/rsa_bb.aspx.
-
September 29th, 2008, 08:36 AM
#8
Re: Who made RSA?
 Originally Posted by cilu
thanks for the links but the Crypto++ is a huge complete library that I don't like to add in my 'little' project 'cos I just need the SHA-256/RSA Algorithm.
The second link is just useful for a high-school project.
-
September 29th, 2008, 09:13 AM
#9
Re: Who made RSA?
What about the CrptoAPI from Microsoft? It's part of the OS and implemented in dlls so doesn't effectively add anything to your code.
-
September 29th, 2008, 04:43 PM
#10
Re: Who made RSA?
 Originally Posted by hoxsiew
What about the CrptoAPI from Microsoft? It's part of the OS and implemented in dlls so doesn't effectively add anything to your code.
I might consider it, thanks for the hint.
I found that one, too: http://www.cs.auckland.ac.nz/~pgut001/cryptlib/
someone knows how to use them?!?!
-
September 30th, 2008, 08:14 AM
#11
Re: Who made RSA?
 Originally Posted by Kirk81
Assuming you are familiar with RSA and private/public key usage, here's some wrappers for common cryptoAPI functions related to RSA. I haven't tested these as such and there's no error checking, but it should be sufficient to get you going.
First, you need to generate a keypair. The following code creates 2 files: private.key and public.key. private.key is encrypted by the passphrase supplied by the user.
Code:
int GenerateRSAKeyPair(void)
{
CFile f;
HCRYPTPROV hProv;
HCRYPTKEY hKey1,hKey2;
HCRYPTHASH hHash;
unsigned char buf[5000];
unsigned long sz=5000;
//Get the ball rolling. Initialize the crypto provider.
CryptAcquireContext(&hProv,NULL,MS_STRONG_PROV,PROV_RSA_FULL,0);
//Create a hash for the password hashed with MD5 (could also use MD2,MD4,SHA,SHA1, or MAC for hashing)
CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
//Use your actual passphrase here
CryptHashData(hHash,(unsigned char *)"passphrase",8,0);
//generate 2048 bit public/private key pair.
CryptGenKey(hProv,CALG_RSA_KEYX,0x08000000|CRYPT_EXPORTABLE,&hKey1);
//clear or buffer (probably not necessary)
memset(buf,0,5000);
//export the public key to the buffer (not to be encrypted)
CryptExportKey(hKey1,0,PUBLICKEYBLOB,0,buf,&sz);//pbData, pdwDataLen);
//save it to a file
f.Open(L"c:\\public.key",CFile::modeCreate|CFile::modeWrite);
f.Write(buf,sz);
f.Close();
//Get a crypto key using out hashed password. They key will use 3DES for encryption
//(could also use DES,3DES_112,DESX,RC2,RC4, or SEAL)
CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey2);
sz=5000;
//export the private key. This is encrypted using the 3DES key
rc=CryptExportKey(hKey1,hKey2,PRIVATEKEYBLOB,0,buf,&sz);
//save to a file
f.Open(L"c:\\private.key",CFile::modeCreate|CFile::modeWrite);
f.Write(buf,sz);
f.Close();
//cleanup
CryptDestroyKey(hKey1);
CryptDestroyKey(hKey2);
CryptDestroyHash(hHash);
CryptReleaseContext(hProv,0);
return 1;
}
Here's code to encrypt data with a public key as created above, and store it into a file called "test.encrypted":
Code:
int RSAEncrypt(void)
{
CFile f;
HCRYPTPROV hProv;
HCRYPTKEY hKey;
unsigned char buf[5000];
unsigned long sz=5000,ctlen;
unsigned char ct[1000];
f.Open(L"c:\\public.key",CFile::modeRead);
sz=f.Read(buf,5000);
f.Close();
CryptAcquireContext(&hProv,NULL,MS_STRONG_PROV,PROV_RSA_FULL,0);
CryptImportKey(hProv,buf,sz,0,CRYPT_EXPORTABLE,&hKey);
ctlen=29;
//Aquire your actual plaintext and copy it to ct.
memcpy(ct,"this is the plaintext string",29);
CryptEncrypt(hKey,NULL,1,0,ct,&ctlen,1000);
f.Open(L"C:\\test.encrypted",CFile::modeCreate|CFile::modeWrite);
f.Write(ct,ctlen);
f.Close();
CryptDestroyKey(hKey);
CryptReleaseContext(hProv,0);
return 1;
}
To decrypt a message in a file "test.encrypted" and encrypted with your public key, use code similar to this:
Code:
int RSADecrypt(void)
{
CFile f;
int rc;
HCRYPTPROV hProv;
HCRYPTHASH hHash;
HCRYPTKEY hKey1;
HCRYPTKEY hKey2;
unsigned char buf[5000];
unsigned long sz=5000,ctlen,ptlen;
unsigned char ct[1000];
f.Open(L"c:\\private.key",CFile::modeRead);
if(!rc){
return 0;
}
//flen=f.GetLength();
sz=f.Read(buf,5000);
f.Close();
CryptAcquireContext(&hProv,NULL,MS_STRONG_PROV,PROV_RSA_FULL,0);
//Create a hash for the password hashed with MD5
CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
CryptHashData(hHash,(unsigned char *)"passphrase",8,0);
CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey2);
rc=CryptImportKey(hProv,buf,sz,hKey2,CRYPT_EXPORTABLE,&hKey1);
if(rc==0){
//bad password.
return 0;
}
f.Open(L"C:\\test.encrypted",CFile::modeRead);
ctlen=f.Read(ct,1000);
f.Close();
ptlen=1000;
CryptDecrypt(hKey1,NULL,1,0,ct,&ctlen); //ct will contain the plaintext
//cleanup.
CryptDestroyKey(hKey1);
CryptDestroyKey(hKey2);
CryptDestroyHash(hHash);
CryptReleaseContext(hProv,0);
return 1;
}
-
September 30th, 2008, 12:23 PM
#12
Re: Who made RSA?
that's for the code. I will use it as example 'cos I need to implement a SHA-256/RSA signature.
And to be honest I'm not sure I can use the Crypto Api from Microsoft in my project cos I'm working with a 'real-time' application.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|