DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Using Blowfish algorythm with Crypto API

  1. #1
    Trong Ha Guest

    Using Blowfish algorythm with Crypto API


    Hi! I got a key was generated by Blowfish algorythm then how can I use it
    with Crypto API. The key length is 56 bytes and I had trouble with importing
    it from CryptImportKey().
    Thanks for all the help from you guys.
    Below are the code I'm using.

    // Clean out the container that we want to use.
    dwReturnCode = CryptAcquireContext(
    &hCryptProv, // [out] HCRYPTPROV *phProv
    "MyKey", // [in] LPCTSTR pszContainer
    MS_ENHANCED_PROV, // [in] LPCTSTR pszProvider
    PROV_RSA_FULL, // [in] DWORD dwProvType
    CRYPT_DELETEKEYSET); // [in] DWORD dwFlags

    if(! dwReturnCode && GetLastError() != NTE_BAD_KEYSET)
    {
    printf("Error during CryptAcquireContext!\n");
    return false;
    }//endif
    else
    {
    if (! CryptAcquireContext(
    &hCryptProv, // [out] HCRYPTPROV *phProv
    "MyContainer", // [in] LPCTSTR pszContainer
    MS_ENHANCED_PROV , // [in] LPCTSTR pszProvider
    PROV_RSA_FULL, // [in] DWORD dwProvType
    CRYPT_NEWKEYSET)) // [in] DWORD dwFlags
    {
    printf("\nError during CryptAcquireContext!\n");
    return false;
    }//end if.
    }//end else.

    printf("Successfully calling CryptAcquireContext...\n");

    dwDataLen = sizeof(BLOB_SessionKey);

    // We now import the session key.
    if(! CryptImportKey(hCryptProv, // [in] HCRYPTPROV hProv
    BLOB_SessionKey, // [in] BYTE* pbData
    dwDataLen, // [in] DWORD dwDataLen
    0, // [in] HCRYPTKEY hPubKey
    0, // [in] DWORD dwFlags
    &hSessionKey)) // [out] HCRYPTKEY* phKey
    {
    printf("Error during CryptImportKey!\n");
    HandleError("Import key error...");
    return false;
    }//endif

    printf("Successfully calling CryptImportKey...\n");


  2. #2
    Trong Ha Guest

    Re: Using Blowfish algorythm with Crypto API


    Hi! I got a key was generated by Blowfish algorythm then how can I use it
    with Crypto API. The key length is 56 bytes and I had trouble with importing
    it from CryptImportKey(). The error code I get back is 80090007.
    Thanks for all the help from you guys.
    Below are the code I'm using.

    // Clean out the container that we want to use.
    dwReturnCode = CryptAcquireContext(
    &hCryptProv, // [out] HCRYPTPROV *phProv
    "MyContainer", // [in] LPCTSTR pszContainer
    MS_ENHANCED_PROV, // [in] LPCTSTR pszProvider
    PROV_RSA_FULL, // [in] DWORD dwProvType
    CRYPT_DELETEKEYSET); // [in] DWORD dwFlags

    if(! dwReturnCode && GetLastError() != NTE_BAD_KEYSET)
    {
    printf("Error during CryptAcquireContext!\n");
    return false;
    }//endif
    else
    {
    if (! CryptAcquireContext(
    &hCryptProv, // [out] HCRYPTPROV *phProv
    "MyContainer", // [in] LPCTSTR pszContainer
    MS_ENHANCED_PROV , // [in] LPCTSTR pszProvider
    PROV_RSA_FULL, // [in] DWORD dwProvType
    CRYPT_NEWKEYSET)) // [in] DWORD dwFlags
    {
    printf("\nError during CryptAcquireContext!\n");
    return false;
    }//end if.
    }//end else.

    printf("Successfully calling CryptAcquireContext...\n");

    dwDataLen = sizeof(BLOB_SessionKey);

    // We now import the session key.
    if(! CryptImportKey(hCryptProv, // [in] HCRYPTPROV hProv
    BLOB_SessionKey, // [in] BYTE* pbData
    dwDataLen, // [in] DWORD dwDataLen
    0, // [in] HCRYPTKEY hPubKey
    0, // [in] DWORD dwFlags
    &hSessionKey)) // [out] HCRYPTKEY* phKey
    {
    printf("Error during CryptImportKey!\n");
    HandleError("Import key error...");
    return false;
    }//endif

    printf("Successfully calling CryptImportKey...\n");


  3. #3
    Jason Bock Guest

    Re: Using Blowfish algorythm with Crypto API

    "Trong Ha" <brandonha@yahoo.com> wrote in message
    news:3b6833a7$1@news.devx.com...
    >
    > Hi! I got a key was generated by Blowfish algorythm then how can I use

    it
    > with Crypto API. The key length is 56 bytes and I had trouble with

    importing
    > it from CryptImportKey().


    Unless you're using a custom provider, the MS providers do not implement the
    Blowfish algorithm, so they don't understand the Blowfish key layout.
    That's probably why you're getting an error.

    Regards,

    Jason



  4. #4
    Trong Ha Guest

    Re: Using Blowfish algorythm with Crypto API


    Could anyone help me to find where I can get Blowfish files (.h, .cpp...)?


    "Jason Bock" <jrbock@removethis.execpc.com> wrote:
    >"Trong Ha" <brandonha@yahoo.com> wrote in message
    >news:3b6833a7$1@news.devx.com...
    >>
    >> Hi! I got a key was generated by Blowfish algorythm then how can I use

    >it
    >> with Crypto API. The key length is 56 bytes and I had trouble with

    >importing
    >> it from CryptImportKey().

    >
    >Unless you're using a custom provider, the MS providers do not implement

    the
    >Blowfish algorithm, so they don't understand the Blowfish key layout.
    >That's probably why you're getting an error.
    >
    >Regards,
    >
    >Jason
    >
    >



  5. #5
    Michael Howard Guest

    Re: Using Blowfish algorythm with Crypto API


    "Trong Ha" <brandonha@yahoo.com> wrote:
    >
    > Hi! I got a key was generated by Blowfish algorythm then how can I use

    it
    >with Crypto API. The key length is 56 bytes and I had trouble with


    capi presently does not support blowfish

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center