首页  >  问答  >  正文

PHP 如何实现java的PbeWithMd5AndDes加密解密

public static String encrypt(String key, String plainText){   String encryptTxt = "";   尝试{    byte[] salt = new byte[8];      MessageDigest md = MessageDigest.getInstance("MD5");      md.update(key.getBytes());      byte[] 摘要 = md.digest();      for (int i = 0; i < 8; i++) {         盐[i] = 摘要[i];      }      PBEKeySpec pbeKeySpec = new PBEKeySpec(key.toCharArray());      SecretKeyFactory keyFactory = SecretKeyFactory            .getInstance("PBEWithMD5AndDES");      SecretKey skey = keyFactory.generateSecret(pbeKeySpec);      PBEParameterSpec paramSpec = new PBEParameterSpec(salt, ITERATIONS);      Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");      cipher.init(Cipher.ENCRYPT_MODE, skey, paramSpec);      byte[] cipherText = cipher.doFinal(plainText.getBytes());      String saltString = new String(Base64.encode(salt));      String ciphertextString = new String(Base64.encode(cipherText));      返回 saltString + ciphertextString;   } catch (Exception e) {      e.printStackTrace();   }   return "";}将bejava加密利用PHP进行解密

七1565 天前2436

全部回复(0)我来回复

暂无回复
  • 取消回复