Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

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");
[1857 byte] By [Trong Ha] at [2007-11-9 23:51:45]
# 1 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");
Trong Ha at 2007-11-12 0:14:53 >
# 2 Re: Using Blowfish algorythm with Crypto API
"Trong Ha" <brandonha@yahoo.com> wrote in message
news:3b6833a7$1@news.dev-archive.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
Jason Bock at 2007-11-12 0:15:58 >
# 3 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.dev-archive.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
>
>
Trong Ha at 2007-11-12 0:16:56 >
# 4 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
Michael Howard at 2007-11-12 0:17:54 >