"Preface" Java Encryption and decryption series, according to the actual development progress, not regularly updated
"Download" Search on the Oracle Web site, unlimited strength jurisdiction Policy files, then select the corresponding authorization file according to the version of JDK installed, for example, my JDK8, I chose this
"Install" After downloading this zip package, there are two jar packages and one Readme.txt file.
Follow the instructions in README.txt to install. Note the JRE used to differentiate the development environment in the JDK, the JRE running the environment is a separate environment. On my Mac, the JRE is installed in the JDK, and the corresponding path is/LIBRARY/JAVA/JAVAVIRTUALMACHINES/JDK1.8.0_102.JDK/CONTENTS/HOME/JRE
Enter the directory where the authorization file is installed
/library/java/javavirtualmachines/jdk1.8.0_102.jdk/contents/home/jre/lib/security can see that the default is to have Local_policy.jar and US_ Export_policy.jar, change the name and save it.
The files in the compressed package are then copied to the/library/java/javavirtualmachines/jdk1.8.0_102.jdk/contents/home/jre/lib/security directory so that the installation is complete.
Authentication
You can use the following procedure to verify
public static void Securityverify () throws Exception {byte[] data = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x
0X07}; Create a-bit secret key from raw bytes Secretkey key64 = new Secretkeyspec (new byte[] {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, "Blowfish"); Create a cipher and attempt to encrypt the data blocks with our key cipher c = cipher.getinstance ("blowfish/
Ecb/nopadding ");
C.init (Cipher.encrypt_mode, key64);
C.dofinal (data);
System.out.println ("bit test:passed"); Create a secret bit key from raw bytes Secretkey key192 = new Secretkeyspec (new byte[) {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x 0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17}, "Blowfish
");
Now try encrypting with the larger key C.init (Cipher.encrypt_mode, key192);
C.dofinal (data);
System.out.println ("test:passed bit");
System.out.println ("Tests completed"); }
If this is the default configuration,
Returns a similar
The bit test:passed
Exception in thread "main" java.lang.SecurityException:
unsupported keysize or algorithm para meters at
javax.crypto.Cipher.init (...)
At Chapter1. Simplepolicytest.main (simplepolicytest.java:38)
If it is replaced, return
Bit test:passed
test:passed
Tests completed