All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.akeyless.crypto.utils.CryptoAlgorithm Maven / Gradle / Ivy

There is a newer version: 0.0.10
Show newest version
package com.akeyless.crypto.utils;

import com.akeyless.exceptions.AkeylessRuntimeException;


public enum CryptoAlgorithm {

    AES_128_GCM("AES128GCM", 16, false),
    AES_256_GCM("AES256GCM", 32, false),

    RSA_1024("RSA1024", 1024, false),
    RSA_2048("RSA2048", 2048, false);

    private final String algName;
    private final int keyLenBytes;
    private final boolean deterministic;

    CryptoAlgorithm(final String algName, final int keyLenBytes, final boolean deterministic) {
        this.algName = algName;
        this.keyLenBytes = keyLenBytes;
        this.deterministic = deterministic;
    }

    public static CryptoAlgorithm getAlgByName(String algName) {
        switch(algName){
            case "AES128GCM":
                return AES_128_GCM;
            case "AES256GCM":
                return AES_256_GCM;
            case "RSA1024":
                return RSA_1024;
            case "RSA2048":
                return RSA_2048;
            default:
                throw new AkeylessRuntimeException("The '"+algName+"' algorithm is not supported");
        }
    }

    public String getAlgName() {
        return algName;
    }

    public int getKeyLenBytes() {
        return keyLenBytes;
    }

    public boolean isDeterministic() {
        return deterministic;
    }

    public boolean isAES() {
        return algName.equals("AES128GCM") || algName.equals("AES256GCM");
    }

    public boolean isRSA() {
        return algName.equals("RSA1024") || algName.equals("RSA2048");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy