Old 11th June 2018, 11:11   #1
otrub
Junior Member
 
Join Date: Mar 2018
Posts: 7
NsisCrypt plugin with AES128 algorithm

Hi all,

I try to use EncryptSymmetric function with aes128 algorithm, but getting an error: "Erro while trying to import key, consider your base64 string! Error Code: 80090008".

It looks like problem with "base64 encoded key" or "base64 encoded iv" I used. Tell me how can I prepare these params from text string (ex. key "123", iv "456").

Thank you.
otrub is offline   Reply With Quote
Old 11th June 2018, 14:22   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,768
Show how you are calling the plug-in! Looking at the Wiki, it does seem like you should base64 encode the key and IV.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 11th June 2018, 18:52   #3
otrub
Junior Member
 
Join Date: Mar 2018
Posts: 7
code:
InitPluginsDir ;make sure we have $pluginsdir
File "/ONAME=$pluginsdir\NsisCrypt.dll" "${NSISDIR}\Plugins\x86-ansi\NsisCrypt.dll" ;you must extract the Ansi plugin manually

;StrCpy $1 "ascii"
CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Hash 2 "123" "md5"
Pop $2
DetailPrint "Hash(123) = $2"

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Hash 2 "456" "md5"
Pop $3
DetailPrint "Hash(456) = $3"

;StrCpy $1 "ascii"
CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" EncryptSymmetric 4 "test string" "aes128" "$2" "$3"
Pop $1
DetailPrint "EncryptSymmetric = $1"



Im newbie in encryption and nsis. Therefore I tried and this code:

code:
InitPluginsDir ;make sure we have $pluginsdir
File "/ONAME=$pluginsdir\NsisCrypt.dll" "${NSISDIR}\Plugins\x86-ansi\NsisCrypt.dll" ;you must extract the Ansi plugin manually

;StrCpy $1 "ascii"
CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Hash 2 "123" "md5"
Pop $2
DetailPrint "Hash(123) = $2"

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Hash 2 "456" "md5"
Pop $3
DetailPrint "Hash(456) = $3"

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Base64Encode 1 "$2"
Pop $4
DetailPrint "Base64Encode(Hash(123)) = $4"

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Base64Encode 1 "$3"
Pop $5
DetailPrint "Base64Encode(Hash(456)) = $5"

;StrCpy $1 "ascii"
CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" EncryptSymmetric 4 "test string" "aes128" "$4" "$5"
Pop $1
DetailPrint "EncryptSymmetric = $1"



And just in case tried this one:

code:
InitPluginsDir ;make sure we have $pluginsdir
File "/ONAME=$pluginsdir\NsisCrypt.dll" "${NSISDIR}\Plugins\x86-ansi\NsisCrypt.dll" ;you must extract the Ansi plugin manually

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Base64Encode 1 "123"
Pop $4
DetailPrint "Base64Encode(Hash(123)) = $4"

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Base64Encode 1 "456"
Pop $5
DetailPrint "Base64Encode(Hash(456)) = $5"

;StrCpy $1 "ascii"
CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" EncryptSymmetric 4 "test string" "aes128" "$4" "$5"
Pop $1
DetailPrint "EncryptSymmetric = $1"



And all trys has one result with error message. I use callansi plugin as opposed to normal way after I visited many forums and only one site told me how to solve other error with unknown chinese words.

With option ascii I had another results of functions but with no victory.
otrub is offline   Reply With Quote
Old 11th June 2018, 18:56   #4
otrub
Junior Member
 
Join Date: Mar 2018
Posts: 7
With another keystring and ivstring I had the same no result.
otrub is offline   Reply With Quote
Old 11th June 2018, 19:13   #5
otrub
Junior Member
 
Join Date: Mar 2018
Posts: 7
code:
InitPluginsDir ;make sure we have $pluginsdir
File "/ONAME=$pluginsdir\NsisCrypt.dll" "${NSISDIR}\Plugins\x86-ansi\NsisCrypt.dll" ;you must extract the Ansi plugin manually

;StrCpy $1 "ascii"
CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Hash 2 "123" "md5"
Pop $2
DetailPrint "Hash(123) = $2"

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Hash 2 "456" "md5"
Pop $3
DetailPrint "Hash(456) = $3"

;StrCpy $1 "ascii"
CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" EncryptSymmetric 4 "test string" "aes128" "$2" "$3"
Pop $1
DetailPrint "EncryptSymmetric = $1"



Im newbie in encryption and nsis. Therefore I tried and this code:

code:
InitPluginsDir ;make sure we have $pluginsdir
File "/ONAME=$pluginsdir\NsisCrypt.dll" "${NSISDIR}\Plugins\x86-ansi\NsisCrypt.dll" ;you must extract the Ansi plugin manually

;StrCpy $1 "ascii"
CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Hash 2 "123" "md5"
Pop $2
DetailPrint "Hash(123) = $2"

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Hash 2 "456" "md5"
Pop $3
DetailPrint "Hash(456) = $3"

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Base64Encode 1 "$2"
Pop $4
DetailPrint "Base64Encode(Hash(123)) = $4"

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Base64Encode 1 "$3"
Pop $5
DetailPrint "Base64Encode(Hash(456)) = $5"

;StrCpy $1 "ascii"
CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" EncryptSymmetric 4 "test string" "aes128" "$4" "$5"
Pop $1
DetailPrint "EncryptSymmetric = $1"



And just in case tried this one:

code:
InitPluginsDir ;make sure we have $pluginsdir
File "/ONAME=$pluginsdir\NsisCrypt.dll" "${NSISDIR}\Plugins\x86-ansi\NsisCrypt.dll" ;you must extract the Ansi plugin manually

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Base64Encode 1 "123"
Pop $4
DetailPrint "Base64Encode(Hash(123)) = $4"

CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" Base64Encode 1 "456"
Pop $5
DetailPrint "Base64Encode(Hash(456)) = $5"

;StrCpy $1 "ascii"
CallAnsiPlugin::Call "$pluginsdir\NsisCrypt" EncryptSymmetric 4 "test string" "aes128" "$4" "$5"
Pop $1
DetailPrint "EncryptSymmetric = $1"



And all trys has one result with error message. I use callansi plugin as opposed to normal way after I visited many forums and only one site told me how to solve other error with unknown chinese words.

With option ascii I had another results of functions but with no victory.
otrub is offline   Reply With Quote
Old 11th June 2018, 19:21   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,768
You should focus on making it work in a ANSI installer first, then you can deal with Unicode later.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 12th June 2018, 07:45   #7
otrub
Junior Member
 
Join Date: Mar 2018
Posts: 7
Ok, I did it. Set Unicode to false. Unfortunately I still have an error "Erro while trying to import key, consider your base64 string! Error Code: 80090008"
otrub is offline   Reply With Quote
Old 12th June 2018, 21:46   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,768
3DES works correctly but AES does not because the plug-in does not use PROV_RSA_AES in the symmetric functions.

After taking a look at the code I'd say the whole thing requires a rewrite, it is leaking memory and does not support Unicode.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 13th June 2018, 17:09   #9
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,768
I played around a bit with a different plug-in and it seems to work:

Quote:
Crypto::Encrypt AES-128 "m:MyKey" "m:MyIV" "m:This is a test"
Pop $3
DetailPrint CT=$3


Crypto::Decrypt AES-128 "m:MyKey" "m:MyIV" "b64:$3"
Pop $4
DetailPrint PT(b64)=$4
Crypto::Decode BASE64 $4
Pop $0
DetailPrint PT=$0


Crypto::DeriveKey AES-128 "m:MyKey"
Pop $1
DetailPrint DK(b64)=$1

Crypto::Decrypt AES-128 "b64:$1" "m:MyIV" "b64:$3"
Pop $0
Crypto::Decode BASE64 $0
Pop $0
DetailPrint PT=$0
Input types are m (narrow string), w (wide string, Unicode only) and b64. The wide string type is a bit useless if you need to read the decrypted data back into a NSIS register because Decrypt returns it as raw UTF-16 encoded as Base64.

The input key is transformed with CryptDeriveKey:SHA1 unless you use the b64 type.

AES is AES CBC with padding.
Attached Files
File Type: zip Crypto 1.5 experimental.zip (7.4 KB, 4 views)

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Tags
aes, nsis, nsiscrypt

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump