Java Utililty Methods Key Create

List of utility methods to do Key Create

  1. HOME
  2. Java
  3. K
  4. Key Create

Description

The list of methods to do Key Create are organized into topic(s).

Method

PrivateKey getKey()
get Key
KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM);
EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(KEY);
return keyFactory.generatePrivate(privateKeySpec);
SecretKey getKey()
Gets the key.
KeySpec keySpec = new PBEKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
return keyFactory.generateSecret(keySpec);
Key getKey()
get Key
try {
 InputStream fis = ClassLoader.getSystemResourceAsStream("key.pk8");
 if (fis == null) {
 throw new RuntimeException("Cannot find keyfile");
 try {
 return KeyFactory.getInstance("RSA")
 .generatePrivate(new PKCS8EncodedKeySpec(getByteArrayFromStream(fis)));
...
Key getKey(byte[] arrayBytesTemp)
get Key
byte[] bytesTemp = new byte[8];
int len = arrayBytesTemp.length < bytesTemp.length ? arrayBytesTemp.length : bytesTemp.length;
for (int i = 0; i < len; i++) {
 bytesTemp[i] = arrayBytesTemp[i];
Key key = new SecretKeySpec(bytesTemp, DEFAULT_ALGORITHM_NAME);
return key;
Key getKey(byte[] keyData)
Instantiates an AES key.
return new SecretKeySpec(keyData, "AES");
Key getKey(InputStream is)
get Key
try {
 ObjectInputStream ois = new ObjectInputStream(is);
 return (Key) ois.readObject();
} catch (Exception e) {
 e.printStackTrace();
 throw new RuntimeException(e);
byte[] getKey(int size)
Generate a random key.
if (size < 1)
 return null; 
byte[] k = new byte[size];
_rand.nextBytes(k);
return k;
Key getKey(KeyStore keystore, String alias, String password)
Get a private key from the keystore by name and password.
return keystore.getKey(alias, password.toCharArray());
PrivateKey getKey(KeyStore keyStore, String password, String orgName)
Loads a private key with the specified org name from a keystore.
try {
 PrivateKey key = (PrivateKey) keyStore.getKey(orgName, password.toCharArray());
 if (key == null) {
 throw new RuntimeException("Unable to get key for " + "name \"" + orgName + "\" using password \""
 + password + "\" from keystore");
 return key;
} catch (Exception e) {
...
T getKey(KeyStore ks, String alias, String pass)
get Key
return (T) ks.getKey(alias, pass.toCharArray());


AltStyle によって変換されたページ (->オリジナル) /