B4J Question Encryption library and .NET

Discussion in 'B4J Questions' started by Juanet, Jul 8, 2015.

  1. Juanet

    Juanet New Member Licensed User


    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:
    ' This one return: BBGWT0W/Tw8=
    Public Sub Encrypt As String
    Dim su As StringUtils 
    Dim c As Cipher
       c.InitialisationVector = su.DecodeBase64(
    Dim Kg As KeyGenerator
    Return su.EncodeBase64(c.Encrypt(su.DecodeBase64("1"), Kg.key, True))
    End Sub
    And here is my .NET code:
    ' 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(
       des.Key = Convert.FromBase64String(
    "QzWZyG+DImE="' => here is the problem, key is to short
       result = Convert.ToBase64String(des.CreateEncryptor().TransformFinalBlock(data, 0, data.Length))
    Return result
    End Function
    Thank you so much.
    Last edited: Jul 9, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.

    Your B4J code uses PKCS5Padding to pad the key as needed. You need to do the same thing in the .Net code.
  3. Juanet

    Juanet New Member Licensed User

    Hi Erel,

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

    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.

    Sorry for that, I go to edit my fisrt post to put the code tags.

    Thanks again.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice