導航:首頁 > 編程語言 > phpchrjava

phpchrjava

發布時間:2022-07-09 07:22:25

A. java getBytes等同於php的什麼

<?php

/**

* byte數組與字元串轉化類

*/

class Bytes {

/**

* 轉換一個String字元串為byte數組

* @param $str 需要轉換的字元串

* @param $bytes 目標byte數組

* @author Zikie

*/
public static function getBytes($string) {
$bytes = array();
for($i = 0; $i < strlen($string); $i++){
$bytes[] = ord($string[$i]);
}
return $bytes;
}

/**

* 將位元組數組轉化為String類型的數據

* @param $bytes 位元組數組

* @param $str 目標字元串

* @return 一個String類型的數據

*/

public static function toStr($bytes) {
$str = '';
foreach($bytes as $ch) {
$str .= chr($ch);
}

return $str;
}

/**

* 轉換一個int為byte數組

* @param $byt 目標byte數組

* @param $val 需要轉換的字元串

*

*/

public static function integerToBytes($val) {
$byt = array();
$byt[0] = ($val & 0xff);
$byt[1] = ($val >> 8 & 0xff);
$byt[2] = ($val >> 16 & 0xff);
$byt[3] = ($val >> 24 & 0xff);
return $byt;
}

/**

* 從位元組數組中指定的位置讀取一個Integer類型的數據

* @param $bytes 位元組數組

* @param $position 指定的開始位置

* @return 一個Integer類型的數據

*/

public static function bytesToInteger($bytes, $position) {
$val = 0;
$val = $bytes[$position + 3] & 0xff;
$val <<= 8;
$val |= $bytes[$position + 2] & 0xff;
$val <<= 8;
$val |= $bytes[$position + 1] & 0xff;
$val <<= 8;
$val |= $bytes[$position] & 0xff;
return $val;
}

/**

* 轉換一個shor字元串為byte數組

* @param $byt 目標byte數組

* @param $val 需要轉換的字元串

*

*/

public static function shortToBytes($val) {
$byt = array();
$byt[0] = ($val & 0xff);
$byt[1] = ($val >> 8 & 0xff);
return $byt;
}

/**

* 從位元組數組中指定的位置讀取一個Short類型的數據。

* @param $bytes 位元組數組

* @param $position 指定的開始位置

* @return 一個Short類型的數據

*/

public static function bytesToShort($bytes, $position) {
$val = 0;
$val = $bytes[$position + 1] & 0xFF;
$val = $val << 8;
$val |= $bytes[$position] & 0xFF;
return $val;
}

}

B. 關於php的crypt加密轉換成java演算法

JAVA 本身有MD5 。。。。。。。。。。。。。

C. Java的異或與PHP的異或,急求解!!!

是1,0,報錯,推出。
相鄰異或,得到一個7位數。試試:看滿意么。

import java.util.Scanner;

class Test {

public static void main(String[] args){

int arr[] = new int[8];
Scanner sc = new Scanner(System.in);
System.out.println("please input the binary number");
String s = sc.next();
if(s.length()==8){

for(int i=0;i<8;i++){
char c = s.charAt(i);
if(c == '1'|| c== '0'){
arr[i] = (int)c;
}else{
System.out.println("the number is wrong");
System.exit(0);

}

}
}else {
System.out.println("the number's length is not 8");
System.exit(0);
}

for(int j=0;j<arr.length-1;j++) {
int k = (arr[j])^(arr[j+1]);
System.out.print(k);
}
}
}

D. 怎麼把php AES128的代碼轉成java

publicclassSimpleCrypto{

publicstaticStringencrypt(Stringseed,Stringcleartext)throwsException{
byte[]rawKey=getRawKey(seed.getBytes());
byte[]result=encrypt(rawKey,cleartext.getBytes());
returntoHex(result);
}

publicstaticStringdecrypt(Stringseed,Stringencrypted)throwsException{
byte[]rawKey=getRawKey(seed.getBytes());
byte[]enc=toByte(encrypted);
byte[]result=decrypt(rawKey,enc);
returnnewString(result);
}

privatestaticbyte[]getRawKey(byte[]seed)throwsException{
KeyGeneratorkgen=KeyGenerator.getInstance("AES");
SecureRandomsr=SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(seed);
kgen.init(128,sr);//
SecretKeyskey=kgen.generateKey();
byte[]raw=skey.getEncoded();
returnraw;
}


privatestaticbyte[]encrypt(byte[]raw,byte[]clear)throwsException{
SecretKeySpecskeySpec=newSecretKeySpec(raw,"AES");
Ciphercipher=Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE,skeySpec);
byte[]encrypted=cipher.doFinal(clear);
returnencrypted;
}

privatestaticbyte[]decrypt(byte[]raw,byte[]encrypted)throwsException{
SecretKeySpecskeySpec=newSecretKeySpec(raw,"AES");
Ciphercipher=Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE,skeySpec);
byte[]decrypted=cipher.doFinal(encrypted);
returndecrypted;
}

publicstaticStringtoHex(Stringtxt){
returntoHex(txt.getBytes());
}
publicstaticStringfromHex(Stringhex){
returnnewString(toByte(hex));
}

publicstaticbyte[]toByte(StringhexString){
intlen=hexString.length()/2;
byte[]result=newbyte[len];
for(inti=0;i<len;i++)
result[i]=Integer.valueOf(hexString.substring(2*i,2*i+2),16).byteValue();
returnresult;
}

publicstaticStringtoHex(byte[]buf){
if(buf==null)
return"";
StringBufferresult=newStringBuffer(2*buf.length);
for(inti=0;i<buf.length;i++){
appendHex(result,buf[i]);
}
returnresult.toString();
}
privatefinalstaticStringHEX="0123456789ABCDEF";
privatestaticvoidappendHex(StringBuffersb,byteb){
sb.append(HEX.charAt((b>>4)&0x0f)).append(HEX.charAt(b&0x0f));
}

}

E. 如何讓php能象java的方式md5加密

<?php//示例代碼:$str = 'hello 這里是php preg_match正則匹配演示';// UTF8編碼:正則表達式匹配中文;if(preg_match('/[\x{4e00}-\x{9fa5}]+/u',$str)){    echo '匹配成功,有中文字元串!';}else{    echo '沒有中文字元串。';}// GB2312,GBK編碼:正則表達式匹配中文;if(preg_match("/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_]+$/",$str)){    echo '匹配成功,有中文字元串!';}else{    echo '沒有中文字元串。';} ?>你看看這樣怎麼樣,建議你去後盾人看看,那裡有教學視頻

閱讀全文

與phpchrjava相關的資料

熱點內容
單片機串列通信有什麼好處 瀏覽:319
游戲開發程序員書籍 瀏覽:843
pdf中圖片修改 瀏覽:268
匯編編譯後 瀏覽:474
php和java整合 瀏覽:829
js中執行php代碼 瀏覽:440
國產單片機廠商 瀏覽:57
蘋果手機怎麼設置不更新app軟體 瀏覽:284
轉行當程序員如何 瀏覽:492
蘋果id怎麼驗證app 瀏覽:864
查看手機命令 瀏覽:953
抖音反編譯地址 瀏覽:226
如何加密軟體oppoa5 瀏覽:233
java從入門到精通明日科技 瀏覽:95
拆解汽車解壓視頻 瀏覽:598
新版百度雲解壓縮 瀏覽:592
android上下拉刷新 瀏覽:880
centos可執行文件反編譯 瀏覽:839
林清玄pdf 瀏覽:271
黑馬程序員java基礎 瀏覽:284