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

io.castled.encryption.EncryptionUtils Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package io.castled.encryption;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Base64;

public class EncryptionUtils {

    public static SecretKey generateKey(int size) throws NoSuchAlgorithmException {
        KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
        keyGenerator.init(size);
        return keyGenerator.generateKey();
    }

    public static String generateEncryptionKey(int size) {
        SecureRandom random = new SecureRandom();
        byte[] encryptionKey = new byte[size];
        random.nextBytes(encryptionKey);
        return Base64.getEncoder().encodeToString(encryptionKey);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy