Security Learning Note 1

Source: Internet
Author: User

Get the Public key object idea:
1, first get the public key pair
Instantiates a Keypairgenerator object with the specified algorithm
Keypairgenerator keygen = keypairgenerator.getinstance ("DSA");
Initialize Keypairgenerator
Keygen.initialize (1024);
Generating KeyPair objects
KeyPair keys = Keygen.genkeypair ();
2. Get the public key byte array
byte[] publickeybytes = Keys.getpublic (). getencoded ();
Instantiating a X509encodedkeyspec object
3. Construct the public key object using the public key byte array.
X509encodedkeyspec KeySpec = new X509encodedkeyspec (publickeybytes);
Instantiates a Keyfactory object with the specified algorithm
Keyfactory keyfactory = keyfactory.getinstance ("DSA");
Get PublicKey Object
Public final PublicKey generatepublic (KeySpec KeySpec) generates a key object based on the provided key specification (keying material).

PublicKey PublicKey = Keyfactory.generatepublic (KeySpec);

The private key creation process is similar to the public key

Algorithmparametergenerator Object creation Process

1. Call the Algorithmparametergenerator.getinstance () method:

1) Call Security.getimpl (algorithm, "Algorithmparametergenerator", (String) null) inside Method getinstance (), and the method returns an array of objects
2) Create a new Algorithmparametergenerator object in the calling constructor with parameters to return
New Algorithmparametergenerator ((ALGORITHMPARAMETERGENERATORSPI) objs[0], (Provider) objs[1], algorithm);

2, initializes this parameter generator for a certain size.
Public final void init (int size)

GetInstance Source:
public static Algorithmparametergenerator getinstance (String algorithm,
String provider)
Throws NoSuchAlgorithmException, Nosuchproviderexception
{
if (Provider = = NULL | | provider.length () = = 0)
throw new IllegalArgumentException ("Missing provider");
object[] Objs = Security.getimpl (algorithm,
"Algorithmparametergenerator",
Provider);
return new Algorithmparametergenerator
(ALGORITHMPARAMETERGENERATORSPI) objs[0], (Provider) objs[1],
algorithm);
}

The internal implementation structure of the getinstance () method of Algorithmparameters, Algorithmparametergenerator, etc. is basically the same.

X509encodedkeyspec for building a public key specification, Pkcs8encodedkeyspec for building a private key specification

The Secretkeyspec interface is the Keyspec implementation class for building secret key specifications

Security Learning Note 1

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.