CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Who made RSA?

  1. #1
    Join Date
    Mar 2002
    Posts
    18

    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.


  2. #2
    Join Date
    Jun 1999
    Location
    San Diego, CA
    Posts
    600

    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 :-)

  3. #3
    Join Date
    Aug 2001
    Location
    Stockholm, Sweden
    Posts
    1,664

    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.

  4. #4
    Join Date
    Mar 2002
    Posts
    18

    Re: Who made RSA?

    Thank you very much


  5. #5
    Join Date
    Sep 2008
    Posts
    33

    Re: Who made RSA?

    do u have an SHA-256/RSA implementation on C/C++?

  6. #6
    Join Date
    Sep 2008
    Posts
    33

    Re: Who made RSA?

    do u have an SHA-256/RSA implementation on C/C++?
    Edit/Delete Message

  7. #7
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  8. #8
    Join Date
    Sep 2008
    Posts
    33

    Wink Re: Who made RSA?

    Quote Originally Posted by cilu
    You could try the CryptoAPI from Microsoft. Or the Crypto++ library. Or this: http://www.codeproject.com/KB/cpp/rsa_bb.aspx.
    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.

  9. #9
    Join Date
    Feb 2005
    Posts
    2,160

    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.

  10. #10
    Join Date
    Sep 2008
    Posts
    33

    Talking Re: Who made RSA?

    Quote 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?!?!

  11. #11
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Who made RSA?

    Quote Originally Posted by Kirk81
    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?!?!
    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;
    }

  12. #12
    Join Date
    Sep 2008
    Posts
    33

    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
  •  





Click Here to Expand Forum to Full Width

Featured