Base64,MD5,Crypt,SSL with Basic4PPC..?

TWELVE

Active Member
Licensed User
Hello agraham,

good news and bad news: the crypt dll works fine so far, but does not return the expected string.

I found this link here, which can calculate the crypt without the need of a own Unix/ Linux pc:

The JavaScript Source: Password Protection: UNIX crypt(3) encryption

I tested it and got exactly the result i expect to get, so you could use it to verify if your lib is using the correct algorithm.

Can you have a look into this again..? I assume now it is the crypt(3) algo as mentioned on wikipedia.Wikipedia also mentions different hash algorithms, maybe there's the crux..?

cheers

TWELVE
 

agraham

Expert
Licensed User
This seems better. I made a typo in the conversion from C to C# code.

EDIT: Web stuff is not my scene but I have just noticed that .NET HTTPWebRequest and HTTPWebResponse classes (as used by the HTTP library) are supposed to support SSL - how you actually do it with certificates or whatever and whether the Door library could do any necessary twiddling I haven't a clue!
 

Attachments

Last edited:

TWELVE

Active Member
Licensed User
Hello agraham,

again thank you very much !!! I just replaced the lib and that's it.It returns now the expected crypt string.I cannot say this enough: your work is an unpayable extension for Basic4PPC and this community here.


EDIT: Web stuff is not my scene but I have just noticed that .NET HTTPWebRequest and HTTPWebResponse classes (as used by the HTTP library) are supposed to support SSL - how you actually do it with certificates or whatever and
The certificate stuff is not so important for my app as it is for public webservers and private web browser, because my client app does know the server and trust it :) So i only need to create my private certificate, and i do not need a CA to approve the certificate, which makes these things easier and cheaper...:))


whether the Door library could do any necessary twiddling I haven't a clue!

I don't have any experience with the door lib yet, so will start to play with it soon...but i don't have a clue either if that works and how it works.


cheers

TWELVE
 

agraham

Expert
Licensed User
I don't have any experience with the door lib yet, so will start to play with it soon...but i don't have a clue either if that works and how it works.
To use it you will have to become at least a little bit familiar with the .NET CLR and the classes it contains :)
 

TWELVE

Active Member
Licensed User
Hello agraham,

i built in a new sub in my app, which works like this:

B4X:
StringToCrypt(passwordstring,saltstring)

salt(0) = Asc(SubString(saltstring,0,1))
salt(1) = Asc(SubString(saltstring,1,1))
...
Return str

I then just replaced my pre-crypted passwordstring

password = "somecryptstring"

against this:


password = StringToCrypt(cleartextpassword,mysalt)


This worked fine, but left me with an rejected/invalid password.By use of my beloved network sniffer :) i found the cause.The returned string has 3 zero bytes at the right end.Zero is not printable, so you can't see that in the msgbox ( it is just not printed).

I though about how i can solve this and came to this here:

For i = 0 To ArrayLen(code())-1
If code(i) <> 0 Then
str = str & Chr(code(i))
End If

Next
I'm assuming, zero is not a valid content for a digit.

This works fine, but i'm asking me, why these 3 upper array fields have been created if their content equals zero...?

Is this something one could view and call as a bug in the lib...? :))


To use it you will have to become at least a little bit familiar with the .NET CLR and the classes it contains
I was afraid this needs to happen someday...:)))


cheers

TWELVE
 
Last edited:

agraham

Expert
Licensed User
I'm assuming, zero is not a valid content for a digit.
This works fine, but i'm asking me, why these 3 upper array fields have been created if their content equals zero...?
Is this something one could view and call as a bug in the lib...? :))
I've examined the output formatting routine of the Crypt source code. This function builds a "C" style string 13 characters long in a fixed length buffer of 16 characters and returns the buffer. "C" style strings are terminated by a zero, so a 13 character string is 14 characters long. That is why the zeroes are there. As a resullt of this convention a "C" string cannot contain a zero character as that would be treated as a terminator. .NET CLR strings are counted and can contain a zero. Why the writer of the original code catered for two extra characters I don't know. However as the returned string is always 13 characters long you can safely just do

For i = 0 to 12
....
Next


EDIT: If you play you may find that a .NET string containing zero doesn't display in, say, a MessageBox. This is because the MessageBox is part of the Windows OS which uses C-style strings and so the MessageBox thinks the zero is a string terminator.
 
Last edited:

TWELVE

Active Member
Licensed User
Hi Andrew,

i'm using your Crypt Lib for a long time now.I just built it in and then forgot about it because it worked as desired.

For some reason now i need to do the reverse direction, i.e. convert back the crypted string to the plain text string again.Apparently the lib already includes that method, but i don't know how to use it.There was no doc file included and i even didn't understand how the code for the string to crypt worked, i just copied most of your example code.

So, can you help out here again and give an example of the crypt to string conversion..?




regards,

TWELVE
 

TWELVE

Active Member
Licensed User
Yes, the CryptDLL you wrote some time ago on my demand.I was in the belief it would be an encryption rather than a hash.Nevertheless thx for the quick reply.

regards,

TWELVE
 

webmaas

Member
Umlauts

Hi there,

thank you so much for this nice and useful lib! There is just one thing that I'm wondering at. Is it possible to Base64-encode german umlauts and special chars? I use your base64.decodeBtoS() for a client-server communication where the use of umlauts is indispensable. Any ideas?
 

webmaas

Member
I think I found a solution for my problem. Please let me know if there is a better way.

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim test As String
   test = "ÖÄÜßäöü€></&%" ' some german umlauts and special chars
   test = ToBase64(test)

   Log(test) ' Log: w5bDhMOcw5/DpMO2w7zigqw+PC8mJQ==
   Log(FromBase64(test)) ' Log: ÖÄÜßäöü€></&%
End Sub

' Encode base64 string
Sub ToBase64 (str As String) As String
   Dim b64 As Base64 
   Dim bc As ByteConverter 
   Dim cypher() As Byte
   
   cypher = bc.StringToBytes(str, "UTF8")
   cypher = b64.EncodeBtoB(cypher, 0, cypher.Length)
   
   Return bc.StringFromBytes(cypher, "UTF8")
End Sub

' Decode bas64 string
Sub FromBase64 (cypher As String) As String
   Dim b64 As Base64 
   Dim bc As ByteConverter 
   Dim str() As Byte
   
   str = bc.StringToBytes(cypher, "UTF8")
   str = b64.DecodeBtoB(str, 0, str.Length)
   
   Return bc.StringFromBytes(str, "UTF8")
End Sub
 
Top