Hilfe: JAVA-verschlüsselte Daten PHP-Entschlüsselung
w
w 2022-07-20 14:14:23
0
2
788

java 加密后的密文:iP6nVfCE9Eiw47utJDR6wV6Lhl4xyOgYykub0HUJSZQ=以下是 java 的 aes 加密类,希望能用 php 解密出来

package com.mk.api.util;import java.security.Key;import java.security.MessageDigest;import java.util.Arrays;import javax.crypto.Cipher;import javax.crypto.spec.SecretKeySpec;import javax.xml.bind.DatatypeConverter;/***AES-Verschlüsselung*/public class AES {   private static final String AESTYPE = " AES";   private static final String KEY = "Z8LSq0wWwB5v+6YJzurcP463H3F12iZh74fDj4S74oUH4EONkiKb2FmiWUbtFh97GG/c/lbDE47mvw6j94yXxKHOpoqu6zpLKMKPcOoSppcVWb2q34qENBJkudXUh4MWcreon dLmLL2UyydtFKuU9Sa5VgY/CzGaVGJABK2ZR94=";     /*** Verschlüsselung * @param content * @return*/   public static String encrypt(String str) {      try {         Key key = genericKey();         Cipher c = Cipher.getInstance(AESTYPE);         c.init(Cipher.ENCRYPT_MODE, Schlüssel);         byte[] encVal = c.doFinal(str.getBytes());         String EncryptedValue = DatatypeConverter.printBase64Binary(encVal);         return cryptovalue;      } Catch (Ausnahme e) {         e.printStackTrace();      }      return null;   }   /*** Entschlüsselung * @param content * @return*/   public static String decrypt(String str) {      try {         Key key = genericKey();         Cipher c = Cipher.getInstance(AESTYPE);         c.init(Cipher.DECRYPT_MODE, Schlüssel);         byte[] decordedValue = DatatypeConverter.parseBase64Binary(str);         byte[] decValue = c.doFinal(decordedValue);         String decryptedValue = new String(decValue);         return decryptedValue;      } Catch (Ausnahme e) {         e.printStackTrace();      }      return null;   }   privater statischer Schlüssel genericKey() löst Ausnahme aus {      byte[] keyValue = KEY.getBytes("UTF-8");      MessageDigest sha = MessageDigest.getInstance("SHA-1");      keyValue = sha.digest(keyValue);      keyValue = Arrays.copyOf(keyValue, 16);      Schlüssel key = new SecretKeySpec(keyValue, AESTYPE);      Eingabetaste;   }   }

w
w

Antworte allen(2)
autoload

看看这个:https://www.php.cn/php-weizijiaocheng-455991.html

w
package com.mk.api.util;

import java.security.Key;
import java.security.MessageDigest;
import java.util.Arrays;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;

/**
 * AES 加密
 */
public class AES {

   private static final String AESTYPE = "AES";
   private static final String KEY = "Z8LSq0wWwB5v+6YJzurcP463H3F12iZh74fDj4S74oUH4EONkiKb2FmiWUbtFh97GG/c/lbDE47mvw6j94yXxKHOpoqu6zpLKMKPcOoSppcVWb2q34qENBJkudXUh4MWcreondLmLL2UyydtFKuU9Sa5VgY/CzGaVGJABK2ZR94=";
   
   /**
    * 加密
    * @param content
    * @return
    */
   public static String encrypt(String str) {
      try {
         Key key = generateKey();
         Cipher c = Cipher.getInstance(AESTYPE);
         c.init(Cipher.ENCRYPT_MODE, key);
         byte[] encVal = c.doFinal(str.getBytes());
         String encryptedValue = DatatypeConverter.printBase64Binary(encVal);
         return encryptedValue;
      } catch (Exception e) {
         e.printStackTrace();
      }
      return null;
   }


   /**
    * 解密
    * @param content
    * @return
    */
   public static String decrypt(String str) {
      try {
         Key key = generateKey();
         Cipher c = Cipher.getInstance(AESTYPE);
         c.init(Cipher.DECRYPT_MODE, key);
         byte[] decordedValue = DatatypeConverter.parseBase64Binary(str);
         byte[] decValue = c.doFinal(decordedValue);
         String decryptedValue = new String(decValue);
         return decryptedValue;
      } catch (Exception e) {
         e.printStackTrace();
      }
      return null;
   }

   private static Key generateKey() throws Exception {
      byte[] keyValue = KEY.getBytes("UTF-8");
      MessageDigest sha = MessageDigest.getInstance("SHA-1");
      keyValue = sha.digest(keyValue);
      keyValue = Arrays.copyOf(keyValue, 16);
      Key key = new SecretKeySpec(keyValue, AESTYPE);
      return key;
   }
   

}

上面代码格式乱了

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage