import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; import org.apache.commons.codec.BinaryDecoder; import org.apache.commons.codec.binary.Hex; public class DESDemo { public static final String src = "des test"; public static void main(String[] args) { jdkDES(); bcDES(); } private static void bcDES() { } private static void jdkDES() { try{ //生成KEY KeyGenerator keyGenerator = KeyGenerator.getInstance("DES"); keyGenerator.init(56); System.out.println(keyGenerator.getAlgorithm()); System.out.println(keyGenerator.getProvider()); SecretKey secretKey = keyGenerator.generateKey(); byte[] bytesKey = secretKey.getEncoded(); System.out.println(secretKey.getAlgorithm()); System.out.println(secretKey.getFormat()); //經過KEY轉換生成密鑰 DESKeySpec desKeySpec = new DESKeySpec(bytesKey); SecretKeyFactory factory = SecretKeyFactory.getInstance("DES"); SecretKey convertedKey = factory.generateSecret(desKeySpec); //加密 Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");// 算法/工做方式/填充方式 cipher.init(Cipher.ENCRYPT_MODE, convertedKey); byte[] result = cipher.doFinal("要加密的內容".getBytes()); System.out.println("jdk des encrypt:" + Hex.encodeHexString(result)); //解密 cipher.init(Cipher.DECRYPT_MODE,convertedKey); result = cipher.doFinal(result); // System.out.println("jdk des decrypt:" + new String(result)); //jdk des decrypt:?????????? 直接輸出會亂碼 System.out.println("jdk des decrypt:" + new String( result,"utf-8" )); //jdk des decrypt:?????????? 依舊亂碼 } catch(Exception e) { e.printStackTrace(); } } }
請問windows系統默認編碼是gbk嗎?java