Skip to content
⌘ NSIS Forum Archive

Crypto Plugin

46 posts

GAG#edited

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
GAG#
Hash Calculator based on Crypto.dll

Hash Calculator:
Example usage of Crypto plugin
GAG#
CryptoNut
Hashing realized via Microsoft CryptoAPI, so if CryptoAPI supports such algo, this algo is supported by plugin too. SHA-1 is already supported.

Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


{ 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]
marcpeterson#
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:


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
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.
sag47#
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
sag47#
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.
sag47#
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
GAG#
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
sag47#
Why was this added to the Wiki?
Note that it will likely to fail with CryptAcquireContext=0x80090016 error on systems prior to WinXP.

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
sag47#
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:
  • Example of the code used to produce error
  • OS and service pack version (of all systems tested on)
  • user privileges on those systems
  • Any other valuable information that you think would lead to producing the error and/or fixing the problem.

Thanks,
SAM
GAG#edited
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.
sag47#
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
7wolves#
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
Animaether#
just gonna cross-reference a post made to a wrong thread here:
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.


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]
GAG#
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
Animaether#
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.
sag47#
CryptAcquireContext=0x80090016
Here is an MSDN article that describes the CryptAcquireContext error codes.



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.
nvit#
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?
sag47#
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.
jdpipe#
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...?
GAG#
Updated Crypto Plugin 1.2

Well...
More then 9 years ago after release of original Crypto Plugin in 2004...
After loosing original sources...
New release!

Crypto Plugin 1.2 build 1030

1.2 - November 25, 2013
  • Fixed CryptAcquireContext NTE_BAD_KEYSET (0x80090016) and NTE_KEYSET_ENTRY_BAD (0x8009001A) errors
  • Technical note: original Crypto.dll was unpacked and patched (CryptAcquireContext call parameters patched; corresponding relocation records removed; version information updated)



Download

Archives attached.

Alternative download links:
  • Crypto Plugin 1.2 build 1030: cryptoplg12.zip 10.3 KB, no installer
  • Crypto Hash Calculator::Crypto Plugin Test: hashcalc12.zip 31.2 KB, no installer


P.S. Opened this forum after last message about Winamp.com and Winamp Media players death. Someone got complete winamp.com archive?
Anders#
There is a copy of this NSIS sub forum but I'm guessing nobody has a copy of all Winamp skins and plugins if that is what you mean...