Java Encryption Decryption (i) Java Encryption System Foundation

Source: Internet
Author: User

Java Encryption Decryption (i) Java Encryption System Foundation1. JCA (Java cryptography Architecture)

Provides basic cryptographic frameworks such as certificates, digital signatures, message digests, and key pair generators. Its main implementation is in the Java.security package.

2. JCE (Java cryptography Extension)

Based on the JCA, the extension provides various cryptographic algorithms, message digest algorithms, and Key management functions. The JCE implementations provided by the JDK are primarily in the Javax.crypto package.
The JCE provided by a third party is also known as the security provider. Due to export restrictions, one or more security providers may be required, bouncy castle is a lightweight, open source, free security provider

3. Security Provider

Implements part or all of Java security, which is a subclass that inherits from Java.security.Provider.
The jre/lib/security/java.security file records the security provider in the JRE environment

Security.provider.1=sun.security.provider.sun
Security.provider.2=sun.security.rsa.sunrsasign
Security.provider.3=sun.security.ec.sunec
Security.provider.4=com.sun.net.ssl.internal.ssl.provider
Security.provider.5=com.sun.crypto.provider.sunjce
Security.provider.6=sun.security.jgss.sunprovider
Security.provider.7=com.sun.security.sasl.provider
Security.provider.8=org.jcp.xml.dsig.internal.dom.xmldsigri
Security.provider.9=sun.security.smartcardio.sunpcsc

3.1 Two ways to add a security provider:

1) Add in the Java.security file
security.provier.<N>=<Provider className>
where n is smaller, the higher the priority, the 1 is the maximum priority.
2) using the Security class
Security.addprovider and Security.insertproviderat methods Add or Insert provider.
Security.addProvider(new BouncyCastleProvider());

Method 1) Adds the security provider to the JRE environment, but is not very portable, if you need to configure the Java.security file again in a different environment.
Method 2) explicitly adds a security provider through code to keep the program running from running environment limits

3.2 Properties of the security provider

The provider class inherits the properties class, so you can use the related method to get the provider property


//查看Provider提供的属性Provider provider = new BouncyCastleProvider(); for(Map.Entry entry : provider.entrySet()) System.out.println(entry.getKey()+": "+entry.getValue());

The keys for these properties define the algorithm name, and the value is the implementation class or algorithm alias for the corresponding algorithm.
The provider internal class service encapsulates these properties and provides a factory method to obtain the corresponding service instance
public synchronized Service getService(String type, String algorithm)
You can see the service types and their algorithms provided by provider in the following ways


Map<String, StringBuilder> typeAlg = new HashMap<String, StringBuilder>(); for (Provider.Service service : provider.getServices()) { if (!typeAlg.containsKey(service.getType())) typeAlg.put(service.getType(), new StringBuilder()); typeAlg.get(service.getType()).append(service.getAlgorithm()).append(","); } for(Map.Entry entry:typeAlg.entrySet()) System.out.println(entry.getKey()+": "+entry.getValue());

Some of the service type and algrithm provided by Bouncycastle are as follows:

Type Algrithm
MessageDigest Sha-1,sha-224,sha-256,sha-384,sha-512,md2,md4,md5
Cipher Aesrfc3211wrap,aeswrap,aes,blowfish,rsa,rsa/raw,rsa/pkcs1
Signature Sha256withcvc-ecdsa,ecdsa,ripemd160withecdsa,sha224withecnr,sha224withcvc-ecdsa,sha256withecnr,sha224withecdsa , SHA384WITHECNR,SHA256WITHECDSA,SHA1WITHCVC-ECDSA,SHA384WITHECDSA,SHA512WITHECDSA,SHA1WITHECNR,SHA512WITHECNR, Nonewithecdsa,md2withrsaencryption,md4withrsaencryption,md5withrsaencryption,sha1withrsaencryption, Sha224withrsaencryption,sha256withrsaencryption,sha384withrsaencryption,sha512withrsaencryption, ripemd160withrsaencryption,ripemd128withrsaencryption,ripemd256withrsaencryption,dsa,nonewithdsa,sha1withrsa/ ISO9796-2,MD5WITHRSA/ISO9796-2,RIPEMD160WITHRSA/ISO9796-2,RSASSA-PSS,1.2.840.113549.1.1.10,SHA1WITHRSA/PSS, SHA224WITHRSA/PSS,SHA256WITHRSA/PSS,SHA384WITHRSA/PSS,SHA512WITHRSA/PSS,RSA,RAWRSASSA-PSS,SHA224WITHDSA, Sha256withdsa,sha384withdsa,sha512withdsa
Keyagreement ECDH,ECDHC,ECMQV,DH,

Java Encryption Decryption (i) Java Encryption System Foundation

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.