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

com.codingapi.springboot.framework.crypto.AESUtils Maven / Gradle / Ivy

There is a newer version: 3.2.6
Show newest version
package com.codingapi.springboot.framework.crypto;

import lombok.SneakyThrows;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class AESUtils {

    /**
     * base64 key
     */
    public final static String key = "QUNEWCQlXiYqJCNYQ1phc0FDRFgkJV4mKiQjWENaYXM=";

    /**
     * base64 iv
     */
    public final static String iv = "QUNYRkdIQEVEUyNYQ1phcw==";


    private final static AESUtils instance = new AESUtils();

    private final AES aes;

    @SneakyThrows
    private AESUtils() {
        this.aes = new AES(Base64.getDecoder().decode(key),Base64.getDecoder().decode(iv));
    }

    public static AESUtils getInstance() {
        return instance;
    }

    public String encode(String input) throws Exception {
        return Base64.getEncoder().encodeToString(aes.encrypt(input.getBytes(StandardCharsets.UTF_8)));
    }

    public String decode(String input) throws Exception {
        return new String(aes.decrypt(Base64.getDecoder().decode(input)),StandardCharsets.UTF_8);
    }

    public byte[] encode(byte[] input) throws Exception {
        return aes.encrypt(input);
    }

    public byte[] decode(byte[] input) throws Exception {
        return aes.decrypt(input);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy