|
From: <php...@li...> - 2007-04-27 22:55:50
|
Hi there --
Ok, I've been working on this a bit today, reading about how classes
constructs are represented in Java and trying to understand the
documentation itself regarding java.security.MessageDigest and I'm just
not sure why it's not liking the update() call. Here's the code
evolution so far:
$password =3D new Java("java.lang.String","admin");
$md =3D new Java("java.security.MessageDigest");
$algorithm =3D $md->getInstance("md5");
$reset =3D $algorithm->reset();
$update =3D $md->update($password->getBytes());
$digest =3D $md->digest();
$out =3D new Java("java.io.ByteArrayOutputStream");
$encoder =3D new Java("javax.mail.internet.MimeUtility");
$encoder->encode($out,"base64");
$encoder->write($encrypted);
$encoder->flush();
$the_return =3D new Java("java.lang.String",$out->toByteArray());
echo "output: ".$the_return->trim();
It tosses an exception at the $update call:
javax.servlet.ServletException: PHP Fatal error: Uncaught
[[o:Exception]:"java.lang.Exception: Invoke failed:
[[c:MessageDigest]]->update([o:array_of_B]). Cause:
java.lang.NoSuchMethodException: update([o:array_of_B]). Candidates: []
Responsible VM: 1.5.0_09@http://java.sun.com/" at:
#-5 php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1106)
#-4 php.java.bridge.Request.handleRequest(Request.java:342)
#-3 php.java.bridge.Request.handleRequests(Request.java:388)
#0 /usr/java/tomcat-5.5/webapps/JavaBridge/test_string.php(24):
Java->__call('update', Array)
#1 /usr/java/tomcat-5.5/webapps/JavaBridge/test_string.php(24):
Java->update(Object(JavaArray))
#2 {main}]
thrown in /usr/java/tomcat-5.5/webapps/JavaBridge/test_string.php on
line 24
php.java.servlet.PhpCGIServlet.doGet(PhpCGIServlet.java:362)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Upon printing $password->getBytes() to the screen it simply resolves,
naturally, to admin. This is correct, I assume, as it's just supposed
to change the series of bytes to the systems character set. =20
So, what is deal?=20
Thanks in advance,
Kate
-----Original Message-----
From: php...@li...
[mailto:php...@li...] On Behalf
Of php...@li...
Sent: Friday, April 27, 2007 2:36 AM
To: php...@li...
Subject: Re: [Php-java-bridge-users] PHP Java Translation Help
Hi,
> algorithm.update(password.getBytes());
> $str =3D new Java('java.lang.String');
> $algorithm->update($str->getBytes($password));
the above PHP code creates a zero-length String and
then calls "".getBytes(<password>). The getBytes()
function needs a symbol as its argument or no argument
at all, not a password. :)
Your Java code translated into PHP is:
<?php
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
$password=3Dnew String("$passwd");
$algorithm=3Djava("java.security.MessageDigest")->getInstance(ENCRYPTION_=
T
YPE);
$algorithm->reset();
$algorithm.update($password->getBytes());
$encrypted =3D $algorithm->digest();
$out =3D new java("java.io.ByteArrayOutputStream");
$encoder =3D
java("javax.mail.internet.MimeUtility")->encode(out,
ENCODING_TYPE);
$encoder->write(encrypted);
$encoder.flush();
return new String(out.toByteArray());
?>
(not tested)
Regards,
Jost Boekemeier
__________________________________ Yahoo! Clever: Sie haben
Fragen? Yahoo! Nutzer antworten Ihnen. www.yahoo.de/clever
------------------------------------------------------------------------
-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
php-java-bridge-users mailing list
php...@li...
https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
|