protected SecretKey getDerivedKey(String algorithm) { return KeyUtils.prepareSecretKey(algorithm, derivedKeyBytes); } }
private static String getSHA1(byte[] input) { try { byte[] digestBytes = KeyUtils.generateDigest(input); return XMLUtils.encodeToString(digestBytes); } catch (WSSecurityException e) { //REVISIT } return null; }
/** * Translate the "cipherAlgo" URI to a JCE ID, and return a javax.crypto.Cipher instance * of this type. * @param cipherAlgo The cipher in it's WSS URI form, * ref. https://www.w3.org/TR/xmlenc-core1/#sec-Algorithms */ public static Cipher getCipherInstance(String cipherAlgo) throws WSSecurityException { return getCipherInstance(cipherAlgo, null); }
symmetricKey = KeyUtils.prepareSecretKey(symEncAlgo, ephemeralKey); } else { KeyGenerator keyGen = KeyUtils.getKeyGenerator(symEncAlgo); symmetricKey = keyGen.generateKey(); ephemeralKey = symmetricKey.getEncoded();
parameters.setStrElement(secRefToken); if (symEncAlgo != null) { parameters.setDerivationKeyLength(KeyUtils.getKeyLength(symEncAlgo)); byte[] secretKey = parserResult.getSecretKey(); principal = parserResult.getPrincipal(); key = KeyUtils.prepareSecretKey(symEncAlgo, secretKey); encrKeyResults = new ArrayList<>(); } else if (encryptedKeyElement != null && data.getWssConfig() != null) { byte[] symmKey = (byte[])encrKeyResults.get(0).get(WSSecurityEngineResult.TAG_SECRET); key = KeyUtils.prepareSecretKey(symEncAlgo, symmKey); } else if (retrievalMethodElement != null && "http://www.w3.org/2001/04/xmlenc#EncryptedKey".equals( if (result != null) { byte[] symmKey = (byte[])result.get(WSSecurityEngineResult.TAG_SECRET); key = KeyUtils.prepareSecretKey(symEncAlgo, symmKey);
private SecretKey getSymmetricKey(String symEncAlgo) throws Exception { synchronized (this) { if (symmetricKey == null) { KeyGenerator keyGen = KeyUtils.getKeyGenerator(symEncAlgo); symmetricKey = keyGen.generateKey(); } return symmetricKey; } }
protected int getDerivedKeyLength() throws WSSecurityException { return derivedKeyLength > 0 ? derivedKeyLength : KeyUtils.getKeyLength(symEncAlgo); }
if (getEphemeralKey() != null) { symmetricKey = KeyUtils.prepareSecretKey(getSymmetricEncAlgorithm(), getEphemeralKey()); } else { KeyGenerator keyGen = KeyUtils.getKeyGenerator(getSymmetricEncAlgorithm()); symmetricKey = keyGen.generateKey();
byte[] decryptedData = X509Util.getSecretKey(keyInfoElement, symEncAlgo, data.getCallbackHandler(), null); symmetricKey = KeyUtils.prepareSecretKey(symEncAlgo, decryptedData); } else { STRParserParameters parameters = new STRParserParameters(); parameters.setStrElement(secRefToken); if (symEncAlgo != null) { parameters.setDerivationKeyLength(KeyUtils.getKeyLength(symEncAlgo)); byte[] secretKey = parserResult.getSecretKey(); principal = parserResult.getPrincipal(); symmetricKey = KeyUtils.prepareSecretKey(symEncAlgo, secretKey);
private SecretKey getSymmetricKey(String symEncAlgo) throws Exception { synchronized (this) { if (symmetricKey == null) { KeyGenerator keyGen = KeyUtils.getKeyGenerator(symEncAlgo); symmetricKey = keyGen.generateKey(); } return symmetricKey; } }
protected int getDerivedKeyLength() throws WSSecurityException { return derivedKeyLength > 0 ? derivedKeyLength : KeyUtils.getKeyLength(sigAlgo); }
@Override public Key getSecretKey(String algorithmURI) throws XMLSecurityException { if (secret != null && algorithmURI != null && !"".equals(algorithmURI)) { return KeyUtils.prepareSecretKey(algorithmURI, secret); } if (key != null) { return key; } if (secret != null) { String jceAlg = JCEMapper.getJCEKeyAlgorithmFromURI(algorithmURI); if (jceAlg == null || "".equals(jceAlg)) { jceAlg = "HmacSHA1"; } return new SecretKeySpec(secret, jceAlg); } return super.getSecretKey(algorithmURI); } };
private static String getSHA1(byte[] input) { try { byte[] digestBytes = KeyUtils.generateDigest(input); return XMLUtils.encodeToString(digestBytes); } catch (WSSecurityException e) { //REVISIT } return null; } }
public static Cipher initCipherWithKey(String keyEncAlgo, String digestAlgo, int mode, Key key) throws WSSecurityException { Cipher cipher = KeyUtils.getCipherInstance(keyEncAlgo); try { OAEPParameterSpec oaepParameters = constructOAEPParameters( keyEncAlgo, digestAlgo, null, null ); if (oaepParameters == null) { cipher.init(mode, key); } else { cipher.init(mode, key, oaepParameters); } } catch (InvalidKeyException | InvalidAlgorithmParameterException e) { throw new WSSecurityException( WSSecurityException.ErrorCode.FAILED_ENCRYPTION, e ); } return cipher; }
private byte[] getSymmetricKey(String symEncAlgo) throws Exception { synchronized (this) { if (symmetricKey == null) { KeyGenerator keyGen = KeyUtils.getKeyGenerator(symEncAlgo); symmetricKey = keyGen.generateKey(); } return symmetricKey.getEncoded(); } }
String algorithmURI = X509Util.getEncAlgo(ee); alg = JCEMapper.getJCEKeyAlgorithmFromURI(algorithmURI); size = KeyUtils.getKeyLength(algorithmURI);
@Override public Key getSecretKey(String algorithmURI) throws XMLSecurityException { if (secret != null && algorithmURI != null && !"".equals(algorithmURI)) { return KeyUtils.prepareSecretKey(algorithmURI, secret); } if (key != null) { return key; } if (secret != null) { String jceAlg = JCEMapper.getJCEKeyAlgorithmFromURI(algorithmURI); if (jceAlg == null || "".equals(jceAlg)) { jceAlg = "HmacSHA1"; } return new SecretKeySpec(secret, jceAlg); } return super.getSecretKey(algorithmURI); } };
private static String getSHA1(byte[] input) { try { byte[] digestBytes = KeyUtils.generateDigest(input); return XMLUtils.encodeToString(digestBytes); } catch (WSSecurityException e) { //REVISIT } return null; } }
public static Cipher initCipherWithKey(String keyEncAlgo, String digestAlgo, int mode, Key key) throws WSSecurityException { Cipher cipher = KeyUtils.getCipherInstance(keyEncAlgo); try { OAEPParameterSpec oaepParameters = constructOAEPParameters( keyEncAlgo, digestAlgo, null, null ); if (oaepParameters == null) { cipher.init(mode, key); } else { cipher.init(mode, key, oaepParameters); } } catch (InvalidKeyException | InvalidAlgorithmParameterException e) { throw new WSSecurityException( WSSecurityException.ErrorCode.FAILED_ENCRYPTION, e ); } return cipher; }
private byte[] getSymmetricKey(String symEncAlgo) throws Exception { synchronized (this) { if (symmetricKey == null) { KeyGenerator keyGen = KeyUtils.getKeyGenerator(symEncAlgo); symmetricKey = keyGen.generateKey(); } return symmetricKey.getEncoded(); } }