java实现DES加密四步走

xiaoxiao2026-04-25  4

用java实现DES加密主要有四步:

import java.security.Key; import java.security.Security; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; public class DESImpl { public static void main(String[] args) throws Exception { String string = "Hello World!"; byte[] bytes = string.getBytes(); // Step 1: Provider support Security.addProvider(new com.sun.crypto.provider.SunJCE()); // Step 2: Get algorithm instance Cipher cipher = Cipher.getInstance("DES"); // Step 3: Initial byte[] keyBytes = "64BitKEY".getBytes(); Key key = new SecretKeySpec(keyBytes, "DES"); cipher.init(Cipher.ENCRYPT_MODE, key); // Step 4: Do final byte[] result = cipher.doFinal(bytes); } }

 

其中密钥KEY为64bit

相关资源:敏捷开发V1.0.pptx
转载请注明原文地址: https://www.6miu.com/read-5047989.html

最新回复(0)