We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
全部文件 >landv-电脑 >软件厂商系统
package main; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; public class Main { private static String encode(String paramString) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException { byte[] arrayOfByte1 = "xxx".getBytes(); SecretKeySpec secretKeySpec = new SecretKeySpec(arrayOfByte1, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); IvParameterSpec ivParameterSpec = new IvParameterSpec(arrayOfByte1); cipher.init(1, secretKeySpec, ivParameterSpec); byte[] arrayOfByte2 = cipher.doFinal(paramString.getBytes()); return byteToHex(arrayOfByte2); } private static String decode(String paramString) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException { byte[] arrayOfByte1 = hexToByte(paramString); byte[] arrayOfByte2 = "xxxx".getBytes(); SecretKeySpec secretKeySpec = new SecretKeySpec(arrayOfByte2, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); IvParameterSpec ivParameterSpec = new IvParameterSpec(arrayOfByte2); cipher.init(2, secretKeySpec, ivParameterSpec); byte[] arrayOfByte3 = cipher.doFinal(arrayOfByte1); return new String(arrayOfByte3); } public static String byteToHex(byte[] paramArrayOfbyte) { if (paramArrayOfbyte == null) return null; StringBuilder stringBuilder = new StringBuilder(2 * paramArrayOfbyte.length); for (byte b : paramArrayOfbyte) stringBuilder.append("0123456789ABCDEF".charAt((b & 0xF0) >> 4)).append("0123456789ABCDEF".charAt(b & 0xF)); return stringBuilder.toString(); } public static byte[] hexToByte(String paramString) { int i = paramString.length(); byte[] arrayOfByte = new byte[i / 2]; for (byte b = 0; b < i; b += 2) arrayOfByte[b / 2] = (byte)((Character.digit(paramString.charAt(b), 16) << 4) + Character.digit(paramString.charAt(b + 1), 16)); return arrayOfByte; } public static void main(String[] paramArrayOfString) throws Exception { String str = encode("xxx"); System.out.println("Encoded password: " + str); System.out.println("fuck:"+decode("xxx")); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
全部文件 >landv-电脑 >软件厂商系统
The text was updated successfully, but these errors were encountered: