/** * 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); }
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; }
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; }
public static Cipher initCipherWithCert( String keyEncAlgo, String digestAlg, int mode, X509Certificate cert ) throws WSSecurityException { Cipher cipher = KeyUtils.getCipherInstance(keyEncAlgo); try { OAEPParameterSpec oaepParameters = constructOAEPParameters( keyEncAlgo, digestAlg, null, null ); if (oaepParameters == null) { cipher.init(mode, cert); } else { cipher.init(mode, cert.getPublicKey(), oaepParameters); } } catch (InvalidKeyException | InvalidAlgorithmParameterException e) { throw new WSSecurityException( WSSecurityException.ErrorCode.FAILED_ENCRYPTION, e ); } return cipher; }
public static Cipher initCipherWithCert( String keyEncAlgo, String digestAlg, int mode, X509Certificate cert ) throws WSSecurityException { Cipher cipher = KeyUtils.getCipherInstance(keyEncAlgo); try { OAEPParameterSpec oaepParameters = constructOAEPParameters( keyEncAlgo, digestAlg, null, null ); if (oaepParameters == null) { cipher.init(mode, cert); } else { cipher.init(mode, cert.getPublicKey(), oaepParameters); } } catch (InvalidKeyException | InvalidAlgorithmParameterException e) { throw new WSSecurityException( WSSecurityException.ErrorCode.FAILED_ENCRYPTION, e ); } return cipher; }
private void encryptSymmetricKey(PublicKey encryptingKey, SecretKey keyToBeEncrypted) throws WSSecurityException { Cipher cipher = KeyUtils.getCipherInstance(keyEncAlgo); try { OAEPParameterSpec oaepParameterSpec = null;
Cipher cipher = KeyUtils.getCipherInstance(encryptedKeyTransportMethod, cryptoProvider); try { OAEPParameterSpec oaepParameterSpec = null;