Code commit for BAEL-4489 (#10790)
* Code commit for "Converting String to BigDecimal in Java" - Article * modified the assert param for comparing actual and expected values * removed the conflict change * Code commit for Secret Key to String and vice versa in java * renaming the junit class name to match coding standard
This commit is contained in:
committed by
GitHub
parent
02595ba791
commit
176c300297
@@ -0,0 +1,44 @@
|
||||
package com.baeldung.secretkeyandstringconversion;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ConversionClassUtilUnitTest {
|
||||
|
||||
@Test
|
||||
void givenPasswordAndSalt_whenCreateSecreKeyCheckConversion_thenSuccess()
|
||||
throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
// given
|
||||
String password = "Baeldung@2021";
|
||||
String salt = "@$#baelDunG@#^$*";
|
||||
|
||||
// when
|
||||
SecretKey encodedKey = ConversionClassUtil.getKeyFromPassword(password, salt);
|
||||
String encodedString = ConversionClassUtil.convertSecretKeyToString(encodedKey);
|
||||
SecretKey decodeKey = ConversionClassUtil.convertStringToSecretKeyto(encodedString);
|
||||
|
||||
// then
|
||||
Assertions.assertEquals(encodedKey, decodeKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenSize_whenCreateSecreKeyCheckConversion_thenSuccess()
|
||||
throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
// given
|
||||
int size = 256;
|
||||
|
||||
// when
|
||||
SecretKey encodedKey = ConversionClassUtil.generateKey(size);
|
||||
String encodedString = ConversionClassUtil.convertSecretKeyToString(encodedKey);
|
||||
SecretKey decodeKey = ConversionClassUtil.convertStringToSecretKeyto(encodedString);
|
||||
|
||||
// then
|
||||
Assertions.assertEquals(encodedKey, decodeKey);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user