|
| 1 | +/* |
| 2 | + * Copyright (C) 2024-2024 OnixByte. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.onixbyte.devkit.utils; |
| 19 | + |
| 20 | +import lombok.extern.slf4j.Slf4j; |
| 21 | +import org.junit.jupiter.api.Assertions; |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | + |
| 24 | +@Slf4j |
| 25 | +public class TestAesUtil { |
| 26 | + |
| 27 | + @Test |
| 28 | + public void testGenerateRandomSecret() { |
| 29 | + log.info("Secret is {}", AesUtil.generateRandomSecret()); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + public void testEncrypt() { |
| 34 | + var secret = "43f72073956d4c81"; |
| 35 | + |
| 36 | + Assertions.assertEquals("IbbYZu8GtMruBURfMBVy/w==", AesUtil.encrypt("Hello World", secret)); |
| 37 | + Assertions.assertEquals("1eVA7oQpTIhI7jc+6cdkmg==", AesUtil.encrypt("OnixByte", secret)); |
| 38 | + Assertions.assertEquals("fk6oNRJK8a+Pz7zVwtlD0UQocq5c3GkRuem0Z6jdAN8=", AesUtil.encrypt("Welcome to use JDevKit!", secret)); |
| 39 | + Assertions.assertEquals("dqzGjawNcQdBpXJWk/08UQ==", AesUtil.encrypt("127.0.0.1", secret)); |
| 40 | + Assertions.assertEquals("uwQQI60yAGL91q9jCDgoeA==", AesUtil.encrypt("root", secret)); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testDecrypt() { |
| 45 | + var secret = "43f72073956d4c81"; |
| 46 | + |
| 47 | + Assertions.assertEquals("Hello World", AesUtil.decrypt("IbbYZu8GtMruBURfMBVy/w==", secret)); |
| 48 | + Assertions.assertEquals("OnixByte", AesUtil.decrypt("1eVA7oQpTIhI7jc+6cdkmg==", secret)); |
| 49 | + Assertions.assertEquals("Welcome to use JDevKit!", AesUtil.decrypt("fk6oNRJK8a+Pz7zVwtlD0UQocq5c3GkRuem0Z6jdAN8=", secret)); |
| 50 | + Assertions.assertEquals("127.0.0.1", AesUtil.decrypt("dqzGjawNcQdBpXJWk/08UQ==", secret)); |
| 51 | + Assertions.assertEquals("root", AesUtil.decrypt("uwQQI60yAGL91q9jCDgoeA==", secret)); |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments