/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] PHP adds funny ascii characters at the end of base64 decryption

I use the following script (the actual example I based mine off of)

[code=php]<?php
$key = ‘That golden key that opes the palace of eternity’;
$data = ‘2345’;
$alg = MCRYPT_BLOWFISH;
$mode = MCRYPT_MODE_CBC;

$iv = mcrypt_create_iv(mcrypt_get_iv_size($alg,$mode),MCRYPT_DEV_URANDOM);
$encrypted_data = mcrypt_encrypt($alg, $key, $data, $mode, $iv);
$plain_text = base64_encode($encrypted_data);

echo $plain_text;
$decoded = mcrypt_decrypt($alg,$key,base64_decode($plain_text),$mode,$iv);
echo $decoded;
?>[/code]

Funny, in Firefox it adds 6 strange ? mark characters to the end of the decryption which I can’t copy and paste into here, but it kinda looks a black diamond with a white question mark inside of it.

Anyway I can get rid of that?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 20.2009 — It's not the base64 stuff, it's the encrypt/decrypt stuff. It pads the data with null characters to fill it out to an integral number of blocks (based on whatever blocksize is being used). You can just rtrim() the final result to get rid of them.
Copy linkTweet thisAlerts:
@cinematic_jesiauthorFeb 25.2009 — Perfect! Thank you! ?
×

Success!

Help @cinematic_jesi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...