|
From: <php...@li...> - 2007-04-28 11:41:58
|
Hi,
I've used the following code:
<?php
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
$passwd="hello";
try {
java_require("mail.jar"); // mail.jar is not part of
the standard jdk
$password=new java("java.lang.String", "$passwd");
$algorithm=java("java.security.MessageDigest")->getInstance("md5");
$algorithm->reset();
$algorithm->update($password->getBytes());
$encrypted = $algorithm->digest();
$out = new java("java.io.ByteArrayOutputStream");
$encoder =
java("javax.mail.internet.MimeUtility")->encode($out,
"base64");
$encoder->write($encrypted);
$encoder->flush();
echo new
java("java.lang.String",$out->toByteArray()); echo
"\n";
exit(0);
} catch (Exception $e) {
echo "Echo invocation failed: $e\n";
//print_r ($e->getTrace());
exit(1);
}
?>
The above PHP script returns the encoded "hello"
string.
> about how classes
> constructs are represented in Java and trying to
The java function is a thin wrapper around the
JavaClass constructor. It is defined in Java.inc as:
function java($clazzName) {
static $cache;
if($cache) return $cache;
return $cache=new JavaClass($clazzName);
}
> $md = new Java("java.security.MessageDigest");
Although our plan was to stop development after the
4.0.8 release, I think it makes sense to add another
4.1.1 release which immediately throws an exception
when the above construct is called. At the moment the
bridge only writes a warning message and only if the
log level is >= 3.
The check could be relaxed and turned into a warning
when -Dphp.java.bridge.enable_deprecated=true is set
(for backward compatibility).
> [[o:Exception]:"java.lang.Exception: Invoke failed:
> [[c:MessageDigest]]->update([o:array_of_B]). Cause:
> java.lang.NoSuchMethodException:
The bridge message is correct. There is no static
"update" method in the MessageDigest class.
I think your Java example uses $algorithm->update(),
not $md->update().
Regards,
Jost Boekemeier
Heute schon einen Blick in die Zukunft von E-Mails wagen? Versuchen Sie´s mit dem neuen Yahoo! Mail. www.yahoo.de/mail
|