public static String decryptWithAsymmetricKey(String data,String encAlgorithm,Key encKey) throws Exception {
  try {
    byte[] tmp=Base64.decode(data);
    Map map=unwrapKeyWithEncodedData(tmp);
    byte[] encData=(byte[])map.get(ENCRYPTED_DATA);
    byte[] keyData=(byte[])map.get(ENCRYPTED_KEY);
    Cipher cipher=Cipher.getInstance(encKey.getAlgorithm());
    cipher.init(Cipher.UNWRAP_MODE,encKey);
    Key secretKey=cipher.unwrap(keyData,encAlgorithm,Cipher.SECRET_KEY);
    cipher=Cipher.getInstance(encAlgorithm);
    cipher.init(Cipher.DECRYPT_MODE,secretKey);
    byte[] decryptedData=cipher.doFinal(encData);
    return Base64.encode(decryptedData);
  }
 catch (  NoSuchAlgorithmException nse) {
    throw new Exception(nse.getMessage());
  }
catch (  InvalidKeyException ike) {
    throw new Exception(ike.getMessage());
  }
}

public static String decryptWithAsymmetricKey ( String data , String encAlgorithm , Key encKey ) throws Exception { try { byte [ ] tmp = Base64 . decode ( data ) ; Map map = unwrapKeyWithEncodedData ( tmp ) ; byte [ ] encData = ( byte [ ] ) map . get ( ENCRYPTED_DATA ) ; byte [ ] keyData = ( byte [ ] ) map . get ( ENCRYPTED_KEY ) ; Cipher cipher = Cipher . getInstance ( encKey . getAlgorithm ( ) ) ; cipher . init ( Cipher . UNWRAP_MODE , encKey ) ; Key secretKey = cipher . unwrap ( keyData , encAlgorithm , Cipher . SECRET_KEY ) ; cipher = Cipher . getInstance ( encAlgorithm ) ; cipher . init ( Cipher . DECRYPT_MODE , secretKey ) ; byte [ ] decryptedData = cipher . doFinal ( encData ) ; return Base64 . encode ( decryptedData ) ; } catch ( NoSuchAlgorithmException nse ) { throw new Exception ( nse . getMessage ( ) ) ; } catch ( InvalidKeyException ike ) { throw new Exception ( ike . getMessage ( ) ) ; } }
decrypts the given data with asymmetric key .
