note 72224 added to ref.mcrypt
| From: | terry200382atgmaildotcom at osu1 dot php dot net | Date: | Mon, 08 Jan 2007 16:00:40 +0000 |
| Subject: | note 72224 added to ref.mcrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121451@lists.php.net to get a copy of this message | ||
To have the same result in Java and PHP with the BouncyCastle library :
/*********
Java
**********/
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
public class tester {
public static void crypter(String password) {
try {
// -- Install jar "bcprov-jdk14-135.jar" in <install_jdk>/jre/lib/ext/
//
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
Cipher cipher = Cipher.getInstance("Blowfish/ECB/ZeroBytePadding");
// -- Substring is used to have no problem with key length
SecretKeySpec keySpec = new SecretKeySpec(password.substring(0,8).getBytes(),
"Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
byte[] outText = cipher.doFinal(password.getBytes());
System.out.println(asHex(outText));
}
catch (Exception e) {
e.printStackTrace();
}
}
public static String asHex (byte buf[]) {
StringBuffer strbuf = new StringBuffer(buf.length * 2);
int i;
for (i = 0; i < buf.length; i++) {
if (((int) buf[i] & 0xff) < 0x10)
strbuf.append("0");
strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
}
return strbuf.toString();
}
public static void main(String[] args) {
try {
crypter("password");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
/********
PHP
*********/
<?php
header("Content-Type: text/plain");
$data = "password";
echo substr($data, 0,8)."\n";
$encrypted_data = mcrypt_ecb(MCRYPT_BLOWFISH, substr($data, 0,8), $data, MCRYPT_ENCRYPT);
echo bin2hex($encrypted_data);
?>
----
Server IP: 217.174.196.197
Probable Submitter: 82.123.184.201
----
Manual Page -- http://www.php.net/manual/en/ref.mcrypt.php
Edit -- https://master.php.net/note/edit/72224
Del: integrated -- https://master.php.net/note/delete/72224/integrated
Del: useless -- https://master.php.net/note/delete/72224/useless
Del: bad code -- https://master.php.net/note/delete/72224/bad+code
Del: spam -- https://master.php.net/note/delete/72224/spam
Del: non-english -- https://master.php.net/note/delete/72224/non-english
Del: in docs -- https://master.php.net/note/delete/72224/in+docs
Del: other reasons-- https://master.php.net/note/delete/72224
Reject -- https://master.php.net/note/reject/72224
Search -- https://master.php.net/manage/user-notes.php