public Cipher toCipher() {
        try {
            val publicKey = getObject();
            if (publicKey != null) {
                val cipher = Cipher.getInstance(this.algorithm);
                cipher.init(Cipher.ENCRYPT_MODE, publicKey);
                LOGGER.trace("Initialized cipher in encrypt-mode via the public key algorithm [{}]", this.algorithm);
                return cipher;
            }
        } catch (final Exception e) {
            LOGGER.warn("Cipher could not be initialized. Error [{}]", e.getMessage());
        }
        return null;
    }
Initialize cipher based on service public key.

@return the false if no public key is found
or if cipher cannot be initialized, etc.
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/crypto/PublicKeyFactoryBean.java