android - Python代碼轉(zhuǎn)為java代碼?
問(wèn)題描述
下面是一段Python的加密代碼 :
import md5def encrypted_id(id): byte1 = bytearray(’3go8&$8*3*3h0k(2)2’) byte2 = bytearray(id) byte1_len = len(byte1) for i in xrange(len(byte2)):byte2[i] = byte2[i]^byte1[i%byte1_len] m = md5.new() m.update(byte2) result = m.digest().encode(’base64’)[:-1] result = result.replace(’/’, ’_’) result = result.replace(’+’, ’-’) return result
請(qǐng)問(wèn)如何改寫(xiě)為java代碼?下面是我改寫(xiě)的java代碼,但是返回的結(jié)果始終為空:
public static String md5(String musicID) throws NoSuchAlgorithmException {System.out.print(musicID);String result;byte[] byte1, byte2;String word = '3go8&$8*3*3h0k(2)2';byte1 = word.getBytes();byte2 = musicID.getBytes();int byte2_len = byte2.length;int byte1_len=byte1.length;for (int i = 0; i < byte2_len; i++) { byte2[i] = (byte) (byte2[i] ^ byte1[i % byte1_len]);}MessageDigest md5 = MessageDigest.getInstance('MD5');md5.update(byte2);byte[] digest = md5.digest();result=new String(Base64.decodeBase64(digest));result = result.replace(’/’, ’_’);result = result.replace(’+’, ’-’);return result; }
問(wèn)題解答
回答1:python md5之后是base64 encode
java md5之后是base64 decode
相關(guān)文章:
1. Python從URL中提取域名2. php傳對(duì)應(yīng)的id值為什么傳不了啊有木有大神會(huì)的看我下方截圖3. python - scrapy url去重4. python - Flask寫(xiě)的注冊(cè)頁(yè)面,當(dāng)注冊(cè)時(shí),如果填寫(xiě)數(shù)據(jù)庫(kù)里有的相同數(shù)據(jù),就報(bào)錯(cuò)5. 關(guān)于mysql聯(lián)合查詢一對(duì)多的顯示結(jié)果問(wèn)題6. 實(shí)現(xiàn)bing搜索工具urlAPI提交7. 數(shù)據(jù)庫(kù) - Mysql的存儲(chǔ)過(guò)程真的是個(gè)坑!求助下面的存儲(chǔ)過(guò)程哪里錯(cuò)啦,實(shí)在是找不到哪里的問(wèn)題了。8. python - oslo_config9. MySQL主鍵沖突時(shí)的更新操作和替換操作在功能上有什么差別(如圖)10. 小白學(xué)python的問(wèn)題 關(guān)于%d和%s的區(qū)別
