View Full Version : Not sure how to use Crypto
marcuslee
25-11-2009, 04:07
Not sure how to use these two commands. Either the example doesn't work or I don't understand what it is suppose to do.
Here's an altered form of the example in the help file:
Uses "Crypto"
Dim sTxt As String
sTxt= Crypto_Encrypt ( "Hello world again!" , "The secret key" , %CRYPTO_CALG_RC2 )
MsgBox 0, sTxt
MsgBox 0, Crypto_Decrypt (sTxt, "The secret key" , %CRYPTO_CALG_RC2 )
With the additional message box, I thought the first message box wouldn't show the contents of sTxt, but it does. The string doesn't seem to be encrypted at all. Am I missing something?
Mark :dog16:
marcuslee
25-11-2009, 04:30
With the additional message box, I thought the first message box wouldn't show the contents of sTxt, but it does. The string doesn't seem to be encrypted at all.
What I expected was something similar that I got from this example:
Uses "Crypto"
Dim sText, fText, kText As String
Dim sPassword As String
sText = "Don't eat yellow snow!"
sPassword = "password"
fText = iCrypto_EncryptRC4(sText, sPassword)
kText = "This is my secret text before decryption:" + Chr$(13) + Chr$(13) + fText
MsgBox 0, kText
fText = iCrypto_DecryptRC4(fText, sPassword)
kText = "This is my secret text after decryption:" + Chr$(13) + Chr$(13) + fText
MsgBox 0, kText
The output before decryption is truly undecipherable ... or at least enough for the average user.
Mark
marcuslee
30-11-2009, 03:24
I was playing around some more with Crypto. I have found another question.
The following script - which is almost exactly like the previous one I posted - it works, but a message box with an OK button appears before the first message box that I put in. That first cryptic box (yes, I had to use the word cryptic ... seemed appropriate) has the title "PowerBasic" and the message: "Exec_iCrypto_EncryptRijndael."
Uses "Crypto"
Dim sText, fText, kText As String
Dim sPassword As String
sText = "Don't eat yellow snow!"
sPassword = "password"
fText = iCrypto_EncryptRijndael(sText, sPassword)
kText = "This is my secret text before decryption:" + Chr$(13) + Chr$(13) + fText
MsgBox 0, kText
fText = iCrypto_DecryptRijndael(fText, sPassword)
kText = "This is my secret text after decryption:" + Chr$(13) + Chr$(13) + fText
MsgBox 0, kText
Is there a way to prevent that first box from appearing?
And, I have figured out some more about the original question from this thread. The RC4 algorithim works with the basic Crypto commands: Crypto_Encrypt & Crypto_Decrypt. The other two mentioned in the help file are the ones that don't work: %Crypto_CALG_RC2 & %Crypto_CALG_DES. The message never is decrypted as far as I can tell. Have the other two been taken out of thinBasic?
Mark
Petr Schreiber
30-11-2009, 09:58
Hi Mark,
I am sorry, but I didn't worked on this module, so I have no idea.
The PowerBASIC titled message box appears when you use MSGBOX in PB code without specified caption.
From this you can only deduce the module has been written in PowerBASIC.
I am not sure, but I think crypto module was not used very intensively, which means it has not been extensively tested in "real world", resulting in such a issues.
Petr
EDIT: I just checked the MSGBOX - it seems it is some debugging information from test times, it should be easy to fix
Petr Schreiber
30-11-2009, 12:10
Regarding the original problem,
Crypto_Encrypt is based on Microsoft's PROV_RSA_FULL Cryptographic Service Provider
When you run SampleScripts/Crypto/ListCryptoProviderType.tBasic, can you see it listed there?
I don't, and that is probably the reason.
Maybe that kind of provider is available on different edition of Windows.
ErosOlmi
30-11-2009, 14:55
I'm working on this issue.
Crypto module has been developed by Roberto Bianchi. I need some time to check what's going on.
hello
i love the surgery solutions, if some freeware crypto dll can be used by thinbasic then it is better than wasting time in correcting and studying old modules, exactly like Eros have done with the IDE, and the recent excellent TImage module addition.
regards
marcuslee
30-11-2009, 17:15
Crypto_Encrypt is based on Microsoft's PROV_RSA_FULL Cryptographic Service Provider
When you run SampleScripts/Crypto/ListCryptoProviderType.tBasic, can you see it listed there?
I don't, and that is probably the reason.
Maybe that kind of provider is available on different edition of Windows.
Sounds like a good reason to me. I ran the script, and I don't know anything about what was listed. Since I got the other icrypto command to work, my question about the original issue just became curiosity. If it only works for certain people on certain machines, perhaps it would be a good idea to make a note of that in the help file.
Concerning the message box: your most likely right, and I had a feeling it would be some sort of debugging feature. I think most of us use message boxes for debugging.
i love the surgery solutions, if some freeware crypto dll can be used by thinbasic then it is better than wasting time in correcting and studying old modules
That's a workable solution. It all depends on your needs, though. If you can avoid major surgery, most people in real life would say skip the surgery. It just depends on how hard it is to fix the old one.
I'm working on this issue.
Crypto module has been developed by Roberto Bianchi. I need some time to check what's going on.
Part of the crypto module works fine, and the part that doesn't work doesn't need to be fixed in my opinion if no one uses it. My suggestion would be to either take out what doesn't work ... or at least document in the help file when it works and doesn't. But, Eros, don't spend time on this because I said something. I'm just a curious kind of person.
I looked into the crypto module because I might want to encrypt some data for a program I want to put together. But, the iCrypto_EncryptRC4 function works just fine ... probably because it is native to thinBasic. If something is dependent on some third party system working, I would rather trust the locals, the natives.
And, I believe that the iCrypto_EncryptRC4 function transforms the source into an encryption of the same number of characters. At least on the small test I did. So, I don't have to worry translating the difference in length.
Love thinBasic! ;)
Mark
ErosOlmi
30-11-2009, 18:14
i love the surgery solutions, if some freeware crypto dll can be used by thinbasic then it is better than wasting time in correcting and studying old modules, exactly like Eros have done with the IDE, and the recent excellent TImage module addition.
Well, having our own code has its advantages.
I will try first to fix the problem or at least understand the reasons why it doesn't work as expected.
In any case source for inspiration is quite big: http://www.pbcrypto.com/pbcrypto.php
Do you see any known names :D check RLE ...
Petr Schreiber
30-11-2009, 20:07
Hehe, yes. But to be fair that Petr Schreiber is my father, I cannot steal credits for his code :)
Sure without him I would never check out PowerBASIC and that means maybe even ThinBASIC would remain unnoticed from my side ... what a terrible vision :)
Michael Clease
30-11-2009, 23:58
Do you see any known names :D check RLE ...
Check mine that I did a while back.
Mike
ErosOlmi
01-12-2009, 09:11
In latest thinBasic beta I've al least removed debug message box.
Regarding "Crypto_Encrypt", I've discovered that that the slave API that do the job (CryptDecrypt (http://msdn.microsoft.com/en-us/library/aa379913(VS.85).aspx)) is returning an error: NTE_BAD_DATA. In Microsoft docs there is this explanation:
The data to be decrypted is not valid. For example, when a block cipher is used and the Final flag is FALSE, the value specified by pdwDataLen must be a multiple of the block size. This error can also be returned when the padding is found to be not valid.
So it seems there is something connected with the data passed or the flags used.
I'm studying the details. I'm sorry I'm not very expert on this field so I need more time to go deeper.
Eros
marcuslee
01-12-2009, 17:06
I'm studying the details. I'm sorry I'm not very expert on this field so I need more time to go deeper.
No one expects you to be super human ... though, you do amaze me a lot. I am sure you have more pressing issues. My suggestion: Don't waste time on something that we have alternative native commands for. The other ways to decrypt seem to work fine, and no one is missing this particular functionality. I would make a note and move on.
Well, that's my two cents, anyway! :unsure:
Mark