B4J Question Encryption library and .NET

Juanet

Member
Licensed User
Longtime User
Hi,

I have a problem when try to get the same results on B4J and .NET using the agraham Encryption library, if somebody can help me with this i will really appreciate.

Here is my B4J code:
B4X:
' This one return: BBGWT0W/Tw8=
Public Sub Encrypt As String
   Dim su As StringUtils 
   Dim c As Cipher
   c.Initialize("DESEDE/CBC/PKCS5Padding")
   c.InitialisationVector = su.DecodeBase64("yKoS+M16uDU=")
   Dim Kg As KeyGenerator
   Kg.Initialize("DESEDE")
   Kg.KeyFromBytes(su.DecodeBase64("QzWZyG+DImE="))
   Return su.EncodeBase64(c.Encrypt(su.DecodeBase64("1"), Kg.key, True))
End Sub

And here is my .NET code:
B4X:
' this one fails,
Function Encrypt() As String
   Dim result As String = ""
   Dim data As Byte() = New UTF8Encoding(False).GetBytes("1")
   Dim des As New TripleDESCryptoServiceProvider()
   des.IV = Convert.FromBase64String("yKoS+M16uDU=")
   des.Key = Convert.FromBase64String("QzWZyG+DImE=") ' => here is the problem, key is to short
   result = Convert.ToBase64String(des.CreateEncryptor().TransformFinalBlock(data, 0, data.Length))
   des.Clear()
   Return result
End Function

Thank you so much.
 
Last edited:

Juanet

Member
Licensed User
Longtime User
Hi Erel,

First of thank you for yours apps that brings devs life more easy.

Your B4J code uses PKCS5Padding to pad the key as needed. You need to do the same thing in the .Net code.
I'm studying Java docs and compare with the MS docs for how to apply correctly the same algorithms, modes and padding with both technologies, also i see that BouncyCastle libs maybe can help me with that.

Please use [code]code here...[/code] tags when posting code.
Sorry for that, I go to edit my fisrt post to put the code tags.

Thanks again.
 
Upvote 0
Top