Hi I want to decrypting my php encrypted string. My code is
UsingPHP.java
import java.io.UnsupportedEncodingException;
import java.u
Well there are two things:
Your encode5t
function returns invalid base64 data. If I call encode5t("malavika")
then the string ==AUVVVeZhlQhdlRspnUsRW
is returned which is not valid base64. The =
sign is the padding and is only allowed at the end of the base64-string. I guess what you wanted is:
function encode5t($value1)
{
for($i=0;$i<3;$i++)
{
$value1=base64_encode(strrev($value1));
}
return $value1;
}
That means you just have to first call strrev
and then base64_encode
. And in the decode-function you first call base64_decode
and then strrev
(or the Java counter-parts).
As I've said in the comment, the second Parameter to Base64.decode in your Java-code is expects flags for the base64-processing and not the length of the string. This might for example turn on the URL_SAFE
flag which makes it incompatible with the output of PHP's base64_encode
.
Hi just change like this.
UsingPHP.java
try
{
System.out.println("Encrypted values going to decrypt......");
byteArray1 = Base64.decode(encrypted_value, Base64.DEFAULT);
System.out.println(byteArray1);
String decrypt = new String(byteArray1, "UTF-8");
System.out.println("Values decrypted-->"+decrypt);
decrypt_txt2.setText(decrypt);
}
encrypt.php
<?php
require_once("connection.php");
$value='dcplsoft';
function encode5t($value1)
{
$value1=base64_encode($value1); // here you will get encrypted value
return $value1;
}
$myvalue=encode5t($value);
$mydata=mysql_query("SELECT * FROM crypt");
while($row = mysql_fetch_assoc( $mydata ))
$sam=$row['value'];
if($sam!='dcplsoft')
$myinsert=mysql_query("insert into crypt values('".$value."','".$myvalue."')") or die (mysql_error());
$data = mysql_query("SELECT * FROM crypt");
while($row = mysql_fetch_assoc( $data ))
$output[]=$row;
print(json_encode($output));
?>