Retrieves a Secret Key using a given Decryption Setup.
@param ds decryption setup
@return SecretKey
189903
static SecretKeySpec readSecretKey(DecryptionSetup ds) {
    Keyed<?> ksObject = DKV.getGet(ds._keystore_id);
    ByteVec ksVec = (ByteVec) (ksObject instanceof Frame ? ((Frame) ksObject).vec(0) : ksObject);
    InputStream ksStream = ksVec.openStream(null /*job key*/);
    try {
      KeyStore keystore = KeyStore.getInstance(ds._keystore_type);
      keystore.load(ksStream, ds._password);

      if (! keystore.containsAlias(ds._key_alias)) {
        throw new IllegalArgumentException("Alias for key not found");
      }

      java.security.Key key = keystore.getKey(ds._key_alias, ds._password);
      return new SecretKeySpec(key.getEncoded(), key.getAlgorithm());
    } catch (GeneralSecurityException e) {
      throw new RuntimeException("Unable to load key " + ds._key_alias + " from keystore " + ds._keystore_id, e);
    } catch (IOException e) {
      throw new RuntimeException("Failed to read keystore " + ds._keystore_id, e);
    }
  }
923301
public static byte[] generateSecretKey() {
    final byte[] k = new byte[KEY_LEN];
    final SecureRandom random = new SecureRandom();
    random.nextBytes(k);
    return k;
  }
245744
@Deprecated
    public Cipher decrypt() {
        try {
            Cipher cipher = Secret.getCipher(KEY_ALGORITHM);
            cipher.init(Cipher.DECRYPT_MODE, getKey());
            return cipher;
        } catch (GeneralSecurityException e) {
            throw new AssertionError(e);
        }
    }
1052755
public byte[] getKey() {
    if (result == null) {
      return null;
    }
    if (result.getKeyData().size() < KEY_LENGTH) {
      throw new IllegalStateException("Could not get enough key data from the handshake.");
    }
    byte[] key = new byte[KEY_LENGTH];
    result.getKeyData().copyTo(key, 0, 0, KEY_LENGTH);
    return key;
  }
773528
public static byte[] getKey(Integer length) {
        if (!AESUtil.SHORT.equals(length) && !AESUtil.MIDDLE.equals(length) && !AESUtil.LONG.equals(length)) {
            throw new RuntimeException("指定的KeySize不正确");
        }
        SecretKey key = null;
        try {
            KeyGenerator keyGen = KeyGenerator.getInstance("AES");
            keyGen.init(length);
            key = keyGen.generateKey();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        return key.getEncoded();
    }
1937
public Key getPrivateKey(String alias, String password) throws UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException {
		return this.keystore.getKey(alias, password.toCharArray());
	}
1025117
public static byte[] generateAesKey(int keysize) {
		try {
			KeyGenerator keyGenerator = KeyGenerator.getInstance(AES_ALG);
			keyGenerator.init(keysize);
			SecretKey secretKey = keyGenerator.generateKey();
			return secretKey.getEncoded();
		} catch (GeneralSecurityException e) {
			throw ExceptionUtil.unchecked(e);
		}
	}
891033
public SecretKey generateKey() {
        SecretKey key = null;
        try {
            KeyGenerator generator = KeyGenerator.getInstance("AES");
            generator.init(128);
            key = generator.generateKey();
        } catch (NoSuchAlgorithmException e) {
            logger.error("Unable to generate AES key", e);
        }

        return key;
    }
340806
public static byte[] AesDecryptByBytes(byte[] encryptBytes,byte[] decryptKey) throws Exception {
		KeyGenerator kgen = KeyGenerator.getInstance("AES");
		SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
		secureRandom.setSeed(decryptKey);
		kgen.init(128,secureRandom);
		Cipher cipher = Cipher.getInstance("AES");
		cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));
		byte[] decryptBytes = cipher.doFinal(encryptBytes);
		return decryptBytes;
	}
114813
public byte[] getSecret (PrivateKey key)
    {
        if (_secret == null) {
            _secret = SecureUtil.decryptBytes(key, _encodedSecret, _salt);
        }
        return _secret;
    }
892256
public SecretKey generateSecretKey() throws NoSuchAlgorithmException {
        final KeyGenerator keyGen = KeyGenerator.getInstance("AES");
        final SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
        keyGen.init(256, random);
        return this.secretKey = keyGen.generateKey();
    }
1324459
public static SecretKey generateKey(String cipherAlgorithm) throws NoSuchAlgorithmException {
        KeyGenerator keyGenerator = KeyGenerator.getInstance(cipherAlgorithm);
        keyGenerator.init(secureRandom);

        return keyGenerator.generateKey();
    }
230350
final static public function get_secret_key() {
        global $CFG;

        if (!isset($CFG->reposecretkey)) {
            set_config('reposecretkey', time() . random_string(32));
        }
        return $CFG->reposecretkey;
    }
116373
public static String decrypt(String encrypted) {
        try {
            return decrypt(encrypted, null);
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
            return null;
        }
    }
150116
public static Cipher getRSACipher (int mode, Key key)
    {
        try {
            Cipher cipher = Cipher.getInstance("RSA");
            cipher.init(mode, key);
            return cipher;
        } catch (GeneralSecurityException gse) {
            log.warning("Failed to create cipher", gse);
        }
        return null;
    }
929478
public static SecretKey generateKey(String algorithm, int keySize) {
        KeyGenerator secretKeyGenerator;
        try {
            secretKeyGenerator = KeyGenerator.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalArgumentException(e);
        }
        secretKeyGenerator.init(keySize);
        return secretKeyGenerator.generateKey();
    }
396951
public Key generateSharedKey() throws KeyException {
        javax.crypto.spec.SecretKeySpec sharedKey = null;
        try {
            if (crypto != null) {
                sharedKey = new javax.crypto.spec.SecretKeySpec(crypto.generate3DESKey(), 0, 24, "3DES");
            }

            if (sharedKey != null) {
                return sharedKey;
            } else {
                throw new com.ibm.websphere.crypto.KeyException("Key could not be generated.");
            }

        } catch (Exception e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(e, "com.ibm.ws.security.audit.AuditEncryptionImpl.generateKey", "98", this);
            if (tc.isDebugEnabled())
                Tr.debug(tc, "Error generating key.", new Object[] { e });

            if (e instanceof KeyException)
                throw (KeyException) e;
            else
                throw new KeyException(e.getMessage(), e);
        }
    }