use of org.opensmartgridplatform.shared.security.EncryptedSecret in project open-smart-grid-platform by OSGP.
the class JreEncryptionProviderTest method identityTest.
@Test
public void identityTest() throws EncrypterException {
final byte[] secret = HexUtils.fromHexString(this.secretString);
final EncryptedSecret encryptedSecret = this.jreEncryptionProvider.encrypt(secret, JRE_KEY_REF);
final String encryptedSecretAsString = HexUtils.toHexString(encryptedSecret.getSecret());
assertEquals("f2edbdc2ad1dab1458f1b866c5a5e6a68873d5738b3742bf3fa5d673133313b6", encryptedSecretAsString);
final byte[] decryptedSecret = this.jreEncryptionProvider.decrypt(encryptedSecret, JRE_KEY_REF);
final String decryptedSecretAsString = HexUtils.toHexString(decryptedSecret);
assertEquals(this.secretString, decryptedSecretAsString);
}
use of org.opensmartgridplatform.shared.security.EncryptedSecret in project open-smart-grid-platform by OSGP.
the class JreEncryptionProviderTest method doErrorTest.
@Test
public void doErrorTest() throws EncrypterException {
final byte[] secret = HexUtils.fromHexString("00000000000000000000000000000000");
final EncryptedSecret encryptedSecret = new EncryptedSecret(this.jreEncryptionProvider.getType(), secret);
assertThrows(EncrypterException.class, () -> this.jreEncryptionProvider.decrypt(encryptedSecret, this.JRE_KEY_REF), "Expected decrypt() to throw javax.crypto.BadPaddingException, but it didn't");
}
Aggregations