Archive: Crypto Plugin


Crypto Plugin
Introduction


This plugin provides you cryptographic interface using CryptoAPI.
Using this plugin you can get common cryptographic hashes like MD5, SHA1, MD2, MD4.

Plugin DLL size: 3 660 bytes (not packed), 2 886 bytes (upx packed)


How to use

1. Hash of string

Crypto::HashData "MD5" "String to be hashed"
Pop $0


Supported algorithms: MD5|SHA1|MD2|MD4

2. Hash of file

Crypto::HashFile "MD5" "$WINDIR\notepad.exe"
Pop $0


Supported algorithms: MD5|SHA1|MD2|MD4

Examples

Hash Calculator: HashCalc.nsi
Simple test: CryptoTest.nsi


Hash Calculator based on Crypto.dll
Hash Calculator:
Example usage of Crypto plugin


SHA-256
Will this possibly support SHA-256 in the future?


Great Plugin!
Great Plugin :) Is there source available for this plugin anywhere?


CryptoNut
Hashing realized via Microsoft CryptoAPI, so if CryptoAPI supports such algo, this algo is supported by plugin too. SHA-1 is already supported.

http://msdn.microsoft.com/library/en...createhash.asp

{ truparu }
Thank you!
Yep, source will be available, when I'll rewrote it from scratch ;) coz I lost my sources ;) [no backup while crash... as always]


CryptAcquireContext error 0x80090016
I've used this dll on my development system without a problem. But when I run the installer on some other systems, I get a CryptAcquireContext error 0x80090016.

I did a bit of digging and found this:
http://support.microsoft.com/default...en-us%3B238187

Do you know if your check for the NTE_BAD_KEYSET as it states on this line?

if (GetLastError() == NTE_BAD_KEYSET)


What are the chances of a new version coming out any time soon? Thanks,

Marc

Hi, Marc
I know about CryptAcquireContext error 0x80090016
It's not related to link you posted.
I used enhanced crypto provider instead of basic one. On some OS enhanced version isn't installed (due to old stupid export limitations or on Win98 w/o IE6 with strong crypto support)
New version of this plugin will be published when I rewrote it from scratch :)
as i already said in prev post, I lost my sources.


Originally posted by GAG
Hi, Marc
I know about CryptAcquireContext error 0x80090016
It's not related to link you posted.
I used enhanced crypto provider instead of basic one. On some OS enhanced version isn't installed (due to old stupid export limitations or on Win98 w/o IE6 with strong crypto support)
New version of this plugin will be published when I rewrote it from scratch :)
as i already said in prev post, I lost my sources.
When you rewrite it can you include support for Whirlpool algorithm possibly? Also your installer puts the documentation in the wrong place. It goes in NSISDIR/Docs/Crypto and the source code (when you rewrite it) should go in NSISDIR/Contrib/Crypto.
SAM

Re: SHA-256

Originally posted by CryptoNut
Will this possibly support SHA-256 in the future?
http :// msdn2. microsoft. com/en-us/library/ms937738.aspx
(had to link this way because now this forum has some dumb link approval system)

Take out the spaces and you'll have your link.
That is all of the supported hash algorithms supported by the CryptAPI.

I've also added a link in the plugin's wiki page on nsis.

Hi GAG,
Hopefully this little snippet will help you rewrite your code faster. Here is a code example I downloaded from another community I belong to that uses the CryptoAPI.
SAM


Here is a slightly modified version of the the one above.


CryptoAPI Plugin NEWS
Hi sag47

Thank you for you support and updated NSIS Wiki page about my plugin.

When you rewrite it can you include support for Whirlpool algorithm possibly?
Whirlpool isn't included in any CrypoAPI implementation, so it can be implemented only using non-CryptoAPI method. If you can explain why Whirlpool is better than SHA-256|512, I'll try to add this algo.

Also your installer puts the documentation in the wrong place.
ok, will be placed in accordance to NSIS folder structure

That is all of the supported hash algorithms supported by the CryptAPI.
just check ALG_ID at MSDN and you'll see this note above CALG_SHA_256:
Windows XP and Windows 2000/NT:: This algorithm is not supported.

the only way to include support for SHA >=256 bits is to create a CryptoAPI-independent implementation which will increase plugin size (I do not really care about disk space anymore :)

well, I'll try to find more time now to implement some of your wishes ;)

P.S. url tag needs to be approved? (see above)
P.P.S. ALG_ID at MSDN: http://msdn2.microsoft.com/en-us/library/aa375549.aspx

Well, the plug is broken not only on 98, but on 2000 as well.

CryptAcquireContext=0x80090016


what do you mean 'broken' ?
plugin was developed on Win2k sp4 and it works OK on many systems


Why was this added to the Wiki?

Note that it will likely to fail with CryptAcquireContext=0x80090016 error on systems prior to WinXP.

http://nsis.sourceforge.net/mediawik...89&oldid=12942
At the moment there doesn't appear to be sufficient research to indicate this problem with the exception of one person whose configuration could itself possibly be broken.

I just tested the cryto 1.1 with the following script test using NSIS v2.34 on Windows 2000 SP4 user privileges only.
 Crypto::HashFile "MD5"  "$WINDIR\notepad.exe"
Pop $0
MessageBox MB_OK $0

The message returned was null and no hash was return yet I didn't get the error like the user above specified so I think before the wiki is edited that further testing is required.
SAM

Originally posted by ********
Well, the plug is broken not only on 98, but on 2000 as well.

CryptAcquireContext=0x80090016
Provide more specs as to how you got that error. Just saying "it's broken" doesn't help with anything. I can't (or don't know how) to produce that error. Please provide the following: Thanks,
SAM

Simply launched HashCalc.exe
Windows2000 SP4
Local Administrator
No domain


NTE_BAD_KEYSET error
Workaround for NTE_BAD_KEYSET error will be added.
Anyway I do not understand, why someone named Techtonik added to wiki article his note about mentioned error in Introduction (!!!) section. If you want to say that it doesn't work on your system, do it in Remarks section, but in Introduction, please.


Re: NTE_BAD_KEYSET error

Originally posted by GAG
Workaround for NTE_BAD_KEYSET error will be added.
Anyway I do not understand, why someone named Techtonik added to wiki article his note about mentioned error in Introduction (!!!) section. If you want to say that it doesn't work on your system, do it in Remarks section, but in Introduction, please.
I don't know how to revert the history of the Wiki (hopefully you do GAG?). I've tried to figure it out with no luck. I'd prefer that the Note it will fail message in the Introduction stay out until whether or not this is a OS wide problem is figured out.
SAM

who can tell me how I can get the source code? Thanks
Who can tell me how I can get the source code?
BTW, I encountered CryptAcquireContext=0x80090016 error in one of my machines with winxp sp2.
Thanks


just gonna cross-reference a post made to a wrong thread here:
http://forums.winamp.com/showthread....82#post2497982

A user saw some odd behavior from the Crypto plugin, in that the Popped value appears empty, while $0 contains the actual result;
[quote]I'd guess that nothing actually gets set on the stack (as the Pop results in the Errors flag being set) and instead the Crypto plugin dumps its result in $0 directly. Not a huge issue (although not encouraged), but something that should probably be noted in the docs.[/code]


see sample script CryptoTest.nsi:


SubSection /e "SHA1"
Section "String Data"
SectionIn 1 2
DetailPrint "${Sep01}"
DetailPrint "SHA1 String Hash"
DetailPrint ""
DetailPrint "Crypto::HashData 'SHA1' '${HashStr}'"
Crypto::HashData "SHA1" "${HashStr}"
Pop $0
DetailPrint "Result:"
DetailPrint "String: '${HashStr}'"
DetailPrint "SHA1: [$0]"
DetailPrint ""
SectionEnd

GAG:


StrCpy $0 "D0"
StrCpy $1 "D1"
Crypto::HashFile "MD5" "$WINDIR\notepad.exe"
ClearErrors
Pop $1
${If} ${Errors}
MessageBox MB_OK "Pop error!"
${EndIf}
MessageBox MB_OK "[$0][$1]"

Throws the Pop error messagebox, and the 2nd messagebox shows that $1 still reads "D1", while $0 shows the MD5 hash.

CryptAcquireContext=0x80090016
Here is an MSDN article that describes the CryptAcquireContext error codes.

http://support.microsoft.com/kb/238187

Thought that would help with further development. Specifically with that error:
NTE_BAD_KEYSET (0x80090016)
  • Key container does not exist.
  • You do not have access to the key container.
  • The Protected Storage Service is not running.

I got CryptAcquireContext=0x80090016 error on 3 of 5 machines with Win XP SP3.
The errors can be shown just by HashCalc.exe.
Is there some workaround?


Crypto plugin has a bug. It's 100%.
So I've replaced it by MD5 plugin


Thanks for posting an alternative. The source appears to be lost for the Crypto Plugin so I don't know if the bug will ever be fixed. I'm not the original creator.


Broken plugin
This plugin fails for me on Windows 7 using the provided 'HashCalc' example. The error NTE_BAD_KEYSET (0x80090016) is given. I built the installer and also tested the resulting HaskCalc on Windows XP and I get the same error.

So I conclude that something might have changed in Windows Crypto and this plugin for NSIS is now completely unusable unless someone works out how to fix it.

Update: it may be that users outside the United States see this error only, if this is something to do with the plugin depending on a hobbled version of some Windows DLL that doesn't provide the required functionality...?