core/src/main/java/com/orientechnologies/orient/core/security/symmetrickey/OSymmetricKey.java
public byte[] decrypt(final String encodedJSON) {
    byte[] result = null;

    if (encodedJSON == null)
      throw new OSecurityException("OSymmetricKey.decrypt(String) encodedJSON is null");

    try {
      byte[] decoded = convertFromBase64(encodedJSON);

      if (decoded == null)
        throw new OSecurityException("OSymmetricKey.decrypt(String) encodedJSON could not be decoded");

      String json = new String(decoded, "UTF8");

      // Convert the JSON content to an ODocument to make parsing it easier.
      final ODocument doc = new ODocument().fromJSON(json, "noMap");

      // Set a default in case the JSON document does not contain an "algorithm" property.
      String algorithm = secretKeyAlgorithm;

      if (doc.containsField("algorithm"))
        algorithm = doc.field("algorithm");

      // Set a default in case the JSON document does not contain a "transform" property.
      String transform = defaultCipherTransformation;

      if (doc.containsField("transform"))
        transform = doc.field("transform");

      String payloadBase64 = doc.field("payload");
      String ivBase64 = doc.field("iv");

      byte[] payload = null;
      byte[] iv = null;

      if (payloadBase64 != null)
        payload = convertFromBase64(payloadBase64);
      if (ivBase64 != null)
        iv = convertFromBase64(ivBase64);

      // Throws NoSuchAlgorithmException and NoSuchPaddingException.
      Cipher cipher = Cipher.getInstance(transform);

      if (iv != null)
        cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iv));
      else
        cipher.init(Cipher.DECRYPT_MODE, secretKey);

      result = cipher.doFinal(payload);
    } catch (Exception ex) {
      throw OException.wrapException(new OSecurityException("OSymmetricKey.decrypt(String) Exception: " + ex.getMessage()), ex);
    }

    return result;
  }
public byte[] decrypt(final String encodedJSON) {
    byte[] result = null;

    if (encodedJSON == null)
      throw new OSecurityException("OSymmetricKey.decrypt(String) encodedJSON is null");

    try {
      byte[] decoded = convertFromBase64(encodedJSON);

      if (decoded == null)
        throw new OSecurityException("OSymmetricKey.decrypt(String) encodedJSON could not be decoded");

      String json = new String(decoded, "UTF8");

      // Convert the JSON content to an ODocument to make parsing it easier.
      final ODocument doc = new ODocument().fromJSON(json, "noMap");

      // Set a default in case the JSON document does not contain an "algorithm" property.
      String algorithm = secretKeyAlgorithm;

      if (doc.containsField("algorithm"))
        algorithm = doc.field("algorithm");

      // Set a default in case the JSON document does not contain a "transform" property.
      String transform = defaultCipherTransformation;

      if (doc.containsField("transform"))
        transform = doc.field("transform");

      String payloadBase64 = doc.field("payload");
      String ivBase64 = doc.field("iv");

      byte[] payload = null;
      byte[] iv = null;

      if (payloadBase64 != null)
        payload = convertFromBase64(payloadBase64);
      if (ivBase64 != null)
        iv = convertFromBase64(ivBase64);

      // Throws NoSuchAlgorithmException and NoSuchPaddingException.
      Cipher cipher = Cipher.getInstance(transform);

      if (iv != null)
        cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iv));
      else
        cipher.init(Cipher.DECRYPT_MODE, secretKey);

      result = cipher.doFinal(payload);
    } catch (Exception ex) {
      throw OException.wrapException(new OSecurityException("OSymmetricKey.decrypt(String) Exception: " + ex.getMessage()), ex);
    }

    return result;
  }
This method decrypts the Base64-encoded JSON document using the specified algorithm and cipher transformation.

@param encodedJSON The Base64-encoded JSON document.

@return The decrypted array of bytes or null if unsuccessful.