Search in sources :

Example 6 with EncryptedSecret

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);
}
Also used : EncryptedSecret(org.opensmartgridplatform.shared.security.EncryptedSecret) Test(org.junit.jupiter.api.Test)

Example 7 with EncryptedSecret

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");
}
Also used : EncryptedSecret(org.opensmartgridplatform.shared.security.EncryptedSecret) Test(org.junit.jupiter.api.Test)

Aggregations

EncryptedSecret (org.opensmartgridplatform.shared.security.EncryptedSecret)7 Test (org.junit.jupiter.api.Test)6 List (java.util.List)3 DbEncryptedSecret (org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret)3 DbEncryptionKeyReference (org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptionKeyReference)3 TypedSecret (org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret)3 Date (java.util.Date)1 Cipher (javax.crypto.Cipher)1 EncrypterException (org.opensmartgridplatform.shared.exceptionhandling.EncrypterException)1