Android Question MCRYPT_RIJNDAEL_256 / Base64

Douglas Farias

Expert
Licensed User
Hi how.
i need to make a base64
encode and decode on b4a with pass but i dont know how it is possible

PHP:
<?php
$Pass = "asasas";
$Clear = "Douglas Farias";       

$crypted = fnEncrypt($Clear, $Pass);
echo "Encrypred: ".$crypted."</br>";

$newClear = fnDecrypt($crypted, $Pass);
echo "Decrypted: ".$newClear."</br>";       

function fnEncrypt($sValue, $sSecretKey)
{
    return rtrim(
        base64_encode(
            mcrypt_encrypt(
                MCRYPT_RIJNDAEL_256,
                $sSecretKey, $sValue,
                MCRYPT_MODE_ECB,
                mcrypt_create_iv(
                    mcrypt_get_iv_size(
                        MCRYPT_RIJNDAEL_256,
                        MCRYPT_MODE_ECB
                    ),
                    MCRYPT_RAND)
                )
            ), "\0"
        );
}

function fnDecrypt($sValue, $sSecretKey)
{
    return rtrim(
        mcrypt_decrypt(
            MCRYPT_RIJNDAEL_256,
            $sSecretKey,
            base64_decode($sValue),
            MCRYPT_MODE_ECB,
            mcrypt_create_iv(
                mcrypt_get_iv_size(
                    MCRYPT_RIJNDAEL_256,
                    MCRYPT_MODE_ECB
                ),
                MCRYPT_RAND
            )
        ), "\0"
    );
} ?>
this php make this.. the result is

Encrypred: sfFrHqVYersOPX/Ie7WEwergWlCzyryQE1Dy4NndXOE=
Decrypted: Douglas Farias
in the b4a i m trying to convert my string to base64 wit, but is not working
B4X:
   Dim su As StringUtils
   Private la As ByteConverter
   Dim data() As Byte  = la.StringToBytes( "Joemil Cassio", "UTF8")
   Private txt As String = su.EncodeBase64(data)
   Log(txt)
the result is Sm9lbWlsIENhc3Npbw==
but i dont know put a pass like the php code
how can i make a decode and encode like this php code on b4a?

thx
 

Douglas Farias

Expert
Licensed User
i see this lib but i dont understand
EncodeStoB (data As String, encoding As String) As Byte()
h
ow to make like php fnEncrypt($Clear, $Pass);
$Pass = "asasas";$Clear = "Douglas Farias";

the Encryption, encode only one string, and not string + pass
can u show a example code pls?
 
Top