Crypto plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(v1.4)
m (SHA2 result)
 
(One intermediate revision by the same user not shown)
Line 11: Line 11:
* '''Download:''' <attach>Crypto.zip</attach>
* '''Download:''' <attach>Crypto.zip</attach>


<div style="background-color:#FFB3B3;border:1px solid #FF1111;color:#A20000;padding:0.4em"><b>Version 1.2 and earlier fails on Windows Server with the NTE_BAD_KEYSET error and should not be used!</b></div>




Line 16: Line 18:


This plug-in allows you to generate cryptographic hashes and random numbers. It uses the [https://msdn.microsoft.com/en-us/library/ms867086.aspx Microsoft Cryptography API] (MS-CAPI).  
This plug-in allows you to generate cryptographic hashes and random numbers. It uses the [https://msdn.microsoft.com/en-us/library/ms867086.aspx Microsoft Cryptography API] (MS-CAPI).  
<div style="background-color:#FFB3B3;border:1px solid #FF1111;color:#A20000;padding:0.3em"><b>Version 1.2 and earlier fails on Windows Server with the NTE_BAD_KEYSET error and should not be used!</b></div>




Line 42: Line 42:
!include LogicLib.nsh
!include LogicLib.nsh
ClearErrors
ClearErrors
Crypto::HashData "SHA2" "Hello World"
Crypto::HashData "SHA2" "How vexingly quick daft zebras jump"
Pop $0
Pop $0
${If} ${Errors}
${If} ${Errors}
DetailPrint "SHA2 not supported, cannot calculate hash!"
DetailPrint "SHA2 not supported, cannot calculate hash!"
${Else}
${Else}
DetailPrint "$0"
DetailPrint "$0" ; 2202BB2E270ED226682C2855AE94144ED192ADB10B5AE9DE93ED4E0A425EA0B6
${EndIf}
${EndIf}
</highlight-nsis>
</highlight-nsis>
Line 79: Line 79:


1.4 - 20160412 - Anders
1.4 - 20160412 - Anders
* Added RNG  
* Added RNG
 


1.3 - 20160406 - Anders
1.3 - 20160406 - [[User:Anders|Anders]]
* Rewritten from scratch
* Rewritten from scratch
* Supports SHA-2 on systems with PROV_RSA_AES
* Supports SHA-2 on systems with PROV_RSA_AES

Latest revision as of 12:10, 26 May 2017

Author: GAG (talk, contrib)


Author: Anders (talk, contrib)


Plug-in Info

  • Version: 1.4
  • Type: Runtime plug-in (Ansi & Unicode)
  • Minimum OS: Win95.OSR2 (IE3+), WinNT4 (IE3+)
  • Minimum NSIS version: 2.45
  • License: Freeware
  • Download: Crypto.zip (3 KB)


Version 1.2 and earlier fails on Windows Server with the NTE_BAD_KEYSET error and should not be used!


Introduction

This plug-in allows you to generate cryptographic hashes and random numbers. It uses the Microsoft Cryptography API (MS-CAPI).


Supported hash algorithms

MD2, MD4, MD5, SHA1, SHA2, SHA2-384, SHA2-512.

The SHA-2 family is only supported on Windows XP.SP3, Windows 2003 with KB938397, and Vista or higher.


Examples

String hash

Crypto::HashData "SHA1" "The quick brown fox jumps over the lazy dog"
Pop $0
DetailPrint Hash=$0 ; 2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12
!include LogicLib.nsh
ClearErrors
Crypto::HashData "SHA2" "How vexingly quick daft zebras jump"
Pop $0
${If} ${Errors}
	DetailPrint "SHA2 not supported, cannot calculate hash!"
${Else}
	DetailPrint "$0" ; 2202BB2E270ED226682C2855AE94144ED192ADB10B5AE9DE93ED4E0A425EA0B6
${EndIf}


File hash

!include LogicLib.nsh
ClearErrors
Crypto::HashFile "MD5" "$ExePath"
Pop $0
${If} ${Errors}
	DetailPrint "Unable to compute the hash!"
${Else}
	DetailPrint "MD5 of myself is $0"
${EndIf}


Random number generator

Crypto::RNG
Pop $0 ; $0 now contains 100 bytes of random data in hex format
StrCpy $0 "0x$0" 18 ; Extract the first 8 bytes
DetailPrint "64-bit random number: $0"


History

1.4 - 20160412 - Anders

  • Added RNG


1.3 - 20160406 - Anders

  • Rewritten from scratch
  • Supports SHA-2 on systems with PROV_RSA_AES
  • Sets the error flag on errors


1.2 - November 25, 2013 - GAG

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


1.1 - May 6, 2004 - GAG

  • Created Hash Calculator example
  • Improved documentation


1.0 - April 7, 2004 - GAG

  • Initial release
  • Supported algorithms: MD5|SHA1|MD2|MD4|MAC


Links