/*
 * Copyright (c) 2024. Elex. All Rights Reesrved.
 * https://www.elex-project.com/
 */

package kr.pe.elex.examples;

import org.junit.jupiter.api.Test;

import javax.crypto.SecretKey;

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Random;

import static org.junit.jupiter.api.Assertions.*;

class AESKeysTest {

	@Test
	void test() throws NoSuchAlgorithmException, InvalidKeySpecException {
		SecretKey secretKey = AESKeys.generateSecretKey();

		String base64SecretKey = AESKeys.encodeSecretKey(secretKey);

		SecretKey secretKey1 = AESKeys.decodeSecretKey(base64SecretKey);

		assertEquals(secretKey, secretKey1);
	}
	@Test
	void test1() throws NoSuchAlgorithmException, InvalidKeySpecException {
		byte[] salt = new byte[8];
		new Random().nextBytes(salt);
		SecretKey secretKey = AESKeys.generateSecretKey("Hello".toCharArray(), salt, 10);

		SecretKey secretKey1 = AESKeys.generateSecretKey("Hello".toCharArray(), salt, 10);

		assertEquals(secretKey, secretKey1);
	}
}