DonChunior Posted May 24, 2023 Share Posted May 24, 2023 I've got a problem where I just can't figure out the cause. 🤔 The simple script below does the following: At the beginning, you can enter a test string. This is then encrypted and temporarily stored in the Credential Manager. Then the data is read again from the Credential Manager and decrypted. Many words (e.g. DonChunior or AutoIt) correspond to the originally entered string after decryption. But for some, for whatever reason I can't figure out, it doesn't?! For example: VeryLongString (the decrypted string is VeryLongStrin) ILoveAutoIt (the decrypted string is ILoveAutoI) WhatIsHereTheProblem (the decrypted string is WhatIsHere) I hope some of you specialists can help me. 🙏 expandcollapse popup#include <Crypt.au3> #include <WinAPIDlg.au3> Main() Func Main() Local $sString = "" Local Const $sCryptKey = "=>J7U\DJ/qFun?Co" Local $dData = Binary("") Local Const $sTarget = "Dummy Credentials" Local $aData = 0 ; Get a string that will be used for testing the encryption and decryption $sString = InputBox("String Input", "Enter a test string:") ConsoleWrite("$sString: " & $sString & @CRLF) _Crypt_Startup() ; Encrypt the previousely entered string $dData = _Crypt_EncryptData(StringToBinary($sString, $SB_UTF8), StringToBinary($sCryptKey, $SB_UTF8), $CALG_RC4) If @error Then ConsoleWrite("_Crypt_EncryptData: @error = " & @error & @CRLF) Exit EndIf ConsoleWrite("$dData: " & $dData & @CRLF) ; Store the encrypted string in the Credential Manager RunWait('cmdkey /generic:"' & $sTarget & '" /user:DummyUserName /pass:"' & BinaryToString($dData) & '"') ; Read the data stored in the Credential Manager $aData = _WinAPI_ShellUserAuthenticationDlg( _ "", _ "", _ "", _ "", _ $sTarget, _ $CREDUI_FLAGS_GENERIC_CREDENTIALS) ConsoleWrite("$aData[0]: " & $aData[0] & @CRLF) ConsoleWrite("$aData[1]: " & $aData[1] & @CRLF) ; Delete the entry in the Credential Manager RunWait('cmdkey /delete:"' & $sTarget & '"') ; Decrypt the data read from the Credential Manager $dData = _Crypt_DecryptData($aData[1], StringToBinary($sCryptKey, $SB_UTF8), $CALG_RC4) If @error Then ConsoleWrite("_Crypt_DecryptData: @error = " & @error & @CRLF) Exit EndIf ConsoleWrite("$dData: " & $dData & @CRLF) _Crypt_Shutdown() ; Convert the data back to a string $sString = BinaryToString($dData, $SB_UTF8) ConsoleWrite("$sString: " & $sString & @CRLF) EndFunc ;==>Main Link to comment Share on other sites More sharing options...
Andreik Posted May 24, 2023 Share Posted May 24, 2023 (edited) Well, when you store the encrypted string in Credential Manager you might end there with some characters that might not be accepted. Let's take for example the string WhatIsHereTheProblem. After you encrypt that string you have a binary like this one 0xD30B275190CF6055989600883E25CDC3D1BA0D9C. It's easy to spot that 11th character is null character (00). Convert that binary to string and you already send messy data to Credential Manager so don't expect anything good when you try to read and decrypt what Credential Manager saved. So it's not about length but about what you get after encryption. You can test that with a string even longer like "Very longggggggggggggggg" and you can see this one doesn't have any problem, but it's just a happy case. Edited May 24, 2023 by Andreik DonChunior 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
DonChunior Posted May 24, 2023 Author Share Posted May 24, 2023 Okay, got it. 👌 It helps quite a bit to know the cause. Now I wonder how to get the encrypted data stored in the Credential Manager. 🙄 Anybody have any ideas? Link to comment Share on other sites More sharing options...
Danyfirex Posted May 24, 2023 Share Posted May 24, 2023 Hello, Maybe using https://stackoverflow.com/questions/9221245/how-do-i-store-and-retrieve-credentials-from-the-windows-vault-credential-manage Saludos DonChunior 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
DonChunior Posted May 24, 2023 Author Share Posted May 24, 2023 5 minutes ago, Danyfirex said: Hello, Maybe using https://stackoverflow.com/questions/9221245/how-do-i-store-and-retrieve-credentials-from-the-windows-vault-credential-manage Saludos That would be the more elaborate plan B if I can't find an easier way. Does anyone else have any ideas? Link to comment Share on other sites More sharing options...
TheXman Posted May 24, 2023 Share Posted May 24, 2023 12 minutes ago, DonChunior said: Does anyone else have any ideas? One of the simplest ways would be to store your encrypted data as text using a binary-to-text encoding scheme like Base64. DonChunior 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Solution DonChunior Posted May 24, 2023 Author Solution Share Posted May 24, 2023 38 minutes ago, TheXman said: One of the simplest ways would be to store your encrypted data as text using a binary-to-text encoding scheme like Base64. I only had to slightly adjust the code in two places so that it now works as expected. 🙂 Line 28 now reads like this: RunWait('cmdkey /generic:"' & $sTarget & '" /user:DummyUserName /pass:"' & String($dData) & '"') And line 45 now reads like this: $dData = _Crypt_DecryptData(Binary($aData[1]), StringToBinary($sCryptKey, $SB_UTF8), $CALG_RC4) The complete script now looks like this: expandcollapse popup#include <Crypt.au3> #include <WinAPIDlg.au3> Main() Func Main() Local $sString = "" Local Const $sCryptKey = "=>J7U\DJ/qFun?Co" Local $dData = Binary("") Local Const $sTarget = "Dummy Credentials" Local $aData = 0 ; Get a string that will be used for testing the encryption and decryption $sString = InputBox("String Input", "Enter a test string:") ConsoleWrite("$sString: " & $sString & @CRLF) _Crypt_Startup() ; Encrypt the previousely entered string $dData = _Crypt_EncryptData(StringToBinary($sString, $SB_UTF8), StringToBinary($sCryptKey, $SB_UTF8), $CALG_RC4) If @error Then ConsoleWrite("_Crypt_EncryptData: @error = " & @error & @CRLF) Exit EndIf ConsoleWrite("$dData: " & $dData & @CRLF) ; Store the encrypted string in the Credential Manager RunWait('cmdkey /generic:"' & $sTarget & '" /user:DummyUserName /pass:"' & String($dData) & '"') ; Read the data stored in the Credential Manager $aData = _WinAPI_ShellUserAuthenticationDlg( _ "", _ "", _ "", _ "", _ $sTarget, _ $CREDUI_FLAGS_GENERIC_CREDENTIALS) ConsoleWrite("$aData[0]: " & $aData[0] & @CRLF) ConsoleWrite("$aData[1]: " & $aData[1] & @CRLF) ; Delete the entry in the Credential Manager RunWait('cmdkey /delete:"' & $sTarget & '"') ; Decrypt the data read from the Credential Manager $dData = _Crypt_DecryptData(Binary($aData[1]), StringToBinary($sCryptKey, $SB_UTF8), $CALG_RC4) If @error Then ConsoleWrite("_Crypt_DecryptData: @error = " & @error & @CRLF) Exit EndIf ConsoleWrite("$dData: " & $dData & @CRLF) _Crypt_Shutdown() ; Convert the data back to a string $sString = BinaryToString($dData, $SB_UTF8) ConsoleWrite("$sString: " & $sString & @CRLF) EndFunc ;==>Main Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now