"Java Encryption" (a) JCE Configure encryption algorithm strength unrestricted authorized installation __java

Source: Internet
Author: User

"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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.