欢迎访问 生活随笔!

凯发ag旗舰厅登录网址下载

当前位置: 凯发ag旗舰厅登录网址下载 > 编程语言 > php >内容正文

php

java 解密 php-凯发ag旗舰厅登录网址下载

发布时间:2025/1/21 php 19 豆豆
凯发ag旗舰厅登录网址下载 收集整理的这篇文章主要介绍了 java 解密 php_使用java解密php解密 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

iv;

$str = $isbinary ? $str : utf8_decode($str);

$td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $iv);

mcrypt_generic_init($td, $this->key, $iv);

$encrypted = mcrypt_generic($td, $str);

mcrypt_generic_deinit($td);

mcrypt_module_close($td);

return $isbinary ? $encrypted : bin2hex($encrypted);

}

function decrypt($code, $isbinary = false) {

$code = $isbinary ? $code : $this->hex2bin($code);

$iv = $this->iv;

$td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $iv);

mcrypt_generic_init($td, $this->key, $iv);

$decrypted = mdecrypt_generic($td, $code);

mcrypt_generic_deinit($td);

mcrypt_module_close($td);

return $isbinary ? trim($decrypted) : utf8_encode(trim($decrypted));

}

protected function hex2bin($hexdata) {

$bindata = '';

for ($i = 0; $i

我的php类来加密图像:encrypt($file, true); //true to set is as binary

file_put_contents($argv[1], $encrypted);

serpro java类:import java.security.nosuchalgorithmexception;

import javax.crypto.cipher;

import javax.crypto.nosuchpaddingexception;

import javax.crypto.spec.ivparameterspec;

import javax.crypto.spec.secretkeyspec;

public class mcrypt {

static char[] hex_chars = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};

private string iv = "fedcba9876543210";//dummy iv (change it!)

private ivparameterspec ivspec;

private secretkeyspec keyspec;

private cipher cipher;

private string secretkey = "0123456789abcdef";//dummy secretkey (change it!)

public mcrypt()

{

ivspec = new ivparameterspec(iv.getbytes());

keyspec = new secretkeyspec(secretkey.getbytes(), "aes");

try {

cipher = cipher.getinstance("aes/cbc/nopadding");

} catch (nosuchalgorithmexception e) {

// todo auto-generated catch block

e.printstacktrace();

} catch (nosuchpaddingexception e) {

// todo auto-generated catch block

e.printstacktrace();

}

}

public byte[] encrypt(string text) throws exception

{

if(text == null || text.length() == 0)

throw new exception("empty string");

byte[] encrypted = null;

try {

cipher.init(cipher.encrypt_mode, keyspec, ivspec);

encrypted = cipher.dofinal(padstring(text).getbytes());

} catch (exception e)

{

throw new exception("[encrypt] "   e.getmessage());

}

return encrypted;

}

public byte[] decrypt(string code) throws exception

{

if(code == null || code.length() == 0)

throw new exception("empty string");

system.out.println("after if");

byte[] decrypted = null;

try {

system.out.println("in try");

cipher.init(cipher.decrypt_mode, keyspec, ivspec);

system.out.println("2");

decrypted = cipher.dofinal(hextobytes(code));

system.out.println("3");

//remove trailing zeroes

if( decrypted.length > 0)

{

system.out.println("in if");

int trim = 0;

for( int i = decrypted.length - 1; i >= 0; i-- ) if( decrypted[i] == 0 ) trim ;

if( trim > 0 )

{

byte[] newarray = new byte[decrypted.length - trim];

system.arraycopy(decrypted, 0, newarray, 0, decrypted.length - trim);

decrypted = newarray;

}

}

system.out.println("after if");

} catch (exception e)

{

throw new exception("[decrypt] "   e.getmessage());

}

return decrypted;

}

public static string bytestohex(byte[] buf)

{

char[] chars = new char[2 * buf.length];

for (int i = 0; i >> 4];

chars[2 * i   1] = hex_chars[buf[i] & 0x0f];

}

return new string(chars);

}

public static byte[] hextobytes(string str) {

if (str==null) {

return null;

} else if (str.length()

我的java类:import java.io.file;

import java.io.fileinputstream;

import java.io.filenotfoundexception;

import java.io.ioexception;

public class decrypt {

public static void main(string[] args) {

file file = new file(args[0]);

fileinputstream fin = null;

try {

fin = new fileinputstream(file);

byte filecontent[] = new byte[(int) file.length()];

fin.read(filecontent);

string filetodecrypt = new string(filecontent);

mcrypt crypter = new mcrypt();

string decrypted = new string(crypter.decrypt(filetodecrypt));

system.out.println(decrypted);

} catch (filenotfoundexception e) {

system.out.println("file not found"   e);

} catch (ioexception ioe) {

system.out.println("exception while reading file "   ioe);

} catch (exception e){

system.out.println("an exception occured: "   e);

} finally {

try {

if (fin != null) {

fin.close();

}

} catch (ioexception ioe) {

system.out.println("error while closing stream: "   ioe);

}

}

}

}

总结

以上是凯发ag旗舰厅登录网址下载为你收集整理的java 解密 php_使用java解密php解密的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。

  • 上一篇:
  • 下一篇:
网站地图