Home  >  Core Java

Example of KeyRep in Java

By Arvind Rai, January 24, 2013
KeyRep belongs to the package java.security. KeyRep is the key representation for the serialized key objects. This class has only one method i.e readResolve and this is protected. The class which will inherit the KeyRep, will give the definition to readResolve. This method is called when the object is deserialized. While creating the object of KeyRep we need the below constructor.
KeyRep(KeyRep.Type type, String algorithm, String format, byte[] encoded)
package com.concretepage.security;
import java.security.Key;
import java.security.KeyRep;
import java.security.KeyRep.Type;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import javax.crypto.KeyGenerator;
public class KeyRepTest {
	public static void main(String... args) throws NoSuchAlgorithmException, NoSuchProviderException{
		KeyGenerator keygen = KeyGenerator.getInstance("AES");
		Key key = keygen.generateKey();
		KeyRep kp= new KeyRep(Type.PUBLIC,key.getAlgorithm(),key.getFormat(),key.getEncoded());
	}
}
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us