Java Key Pair Create generateKeyFromString(final String secKey, String algorithm)

Here you can find the source of generateKeyFromString(final String secKey, String algorithm)

Description

generate Key From String

License

Apache License

Declaration

public static Key generateKeyFromString(final String secKey, String algorithm) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.security.Key;
import java.util.Base64;
import javax.crypto.spec.SecretKeySpec;

public class Main {
    public static Key generateKeyFromString(final String secKey, String algorithm) throws Exception {

        final byte[] keyVal = Base64.getDecoder().decode(secKey.getBytes());
        final Key key = new SecretKeySpec(keyVal, algorithm);
        return key;
    }/*from  www .j  av  a 2  s  .  co  m*/

    public static Key generateKeyFromString(final byte[] secKey, String algorithm) throws Exception {

        final Key key = new SecretKeySpec(secKey, algorithm);
        return key;
    }
}

Related

  1. generateKey(String seed)
  2. generateKey(String type)
  3. generateKey(String userKey, String masterKey)
  4. generateKeyAES()
  5. generateKeyDigest(int keyLength, String password)
  6. generateKeyPair()
  7. generateKeyPair()
  8. generateKeyPair()
  9. generateKeyPair()