class OutlookFolderCreatorPasswordMd5ToSha256UpdateExecutor implements AcmDataUpdateExecutor {

    public void updateOutlookFolderCreatorPasswords()
    {
        List<AcmOutlookFolderCreator> folderCreators = getEntityManager()
                .createQuery("SELECT e FROM AcmOutlookFolderCreator e", AcmOutlookFolderCreator.class).getResultList();

        log.info("{} folder creators to check", folderCreators.size());

        for (AcmOutlookFolderCreator folderCreator : folderCreators)
        {
            log.debug("checking folder creator {}", folderCreator.getSystemEmailAddress());

            // can we decrypt with md5 hash? If so, we need to re-encrypt it with SHA256
            try
            {
                byte[] decrypted = getCryptoUtils().decryptData(
                        getCryptoProperties().getSymmetricKey(),
                        Base64.getDecoder().decode(folderCreator.getSystemPassword()),
                        getCryptoProperties().getPropertiesEncryptionKeySize(),
                        getCryptoProperties().getPropertiesEncryptionIVSize(),
                        getCryptoProperties().getPropertiesEncryptionMagicSize(),
                        getCryptoProperties().getPropertiesEncryptionSaltSize(),
                        getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(),
                        "MD5",
                        getCryptoProperties().getPropertiesEncryptionAlgorithm(),
                        getCryptoProperties().getPropertiesEncryptionBlockCipherMode(),
                        getCryptoProperties().getPropertiesEncryptionPadding());
                log.debug("{} password is MD5-hashed, proceeding with update", folderCreator.getSystemEmailAddress());

                byte[] encrypted = getCryptoUtils().encryptData(
                        getCryptoProperties().getSymmetricKey(),
                        decrypted,
                        getCryptoProperties().getPropertiesEncryptionKeySize(),
                        getCryptoProperties().getPropertiesEncryptionIVSize(),
                        getCryptoProperties().getPropertiesEncryptionMagicSize(),
                        getCryptoProperties().getPropertiesEncryptionSaltSize(),
                        getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(),
                        getCryptoProperties().getPropertiesEncryptionPassPhraseHashAlgorithm(),
                        getCryptoProperties().getPropertiesEncryptionAlgorithm(),
                        getCryptoProperties().getPropertiesEncryptionBlockCipherMode(),
                        getCryptoProperties().getPropertiesEncryptionPadding());
                String encryptedBase64 = Base64.getEncoder().encodeToString(encrypted);
                folderCreator.setSystemPassword(encryptedBase64);
                getEntityManager().merge(folderCreator);
            }
            catch (AcmEncryptionException ace)
            {
                log.debug("{} password is not MD5-hashed, no need to update it", folderCreator.getSystemEmailAddress());
            }
        }

        log.info("Done checking {} folder creators", folderCreators.size());

    }

}