Search in sources :

Example 6 with CryptoException

use of io.nem.symbol.core.crypto.CryptoException in project nem2-sdk-java by nemtech.

the class EncryptedMessageTest method testDecryptWrong.

@Test
public void testDecryptWrong() {
    String wrongEncrypted = "ABCD";
    KeyPair sender = KeyPair.random();
    KeyPair recipient = KeyPair.random();
    EncryptedMessage encryptedMessage = new EncryptedMessage(wrongEncrypted);
    Assertions.assertEquals(MessageType.ENCRYPTED_MESSAGE, encryptedMessage.getType());
    CryptoException e = Assertions.assertThrows(CryptoException.class, () -> encryptedMessage.decryptPayload(sender.getPublicKey(), recipient.getPrivateKey()));
    Assertions.assertEquals("Cannot decrypt input. Size is 2 when at least 28 is expected.", e.getMessage());
}
Also used : KeyPair(io.nem.symbol.core.crypto.KeyPair) CryptoException(io.nem.symbol.core.crypto.CryptoException) Test(org.junit.jupiter.api.Test)

Aggregations

CryptoException (io.nem.symbol.core.crypto.CryptoException)6 KeyPair (io.nem.symbol.core.crypto.KeyPair)3 Test (org.junit.jupiter.api.Test)3 BlockCipher (io.nem.symbol.core.crypto.BlockCipher)2 BlockCipherTest (io.nem.symbol.core.crypto.BlockCipherTest)2 CryptoEngine (io.nem.symbol.core.crypto.CryptoEngine)2 InvalidCipherTextException (org.bouncycastle.crypto.InvalidCipherTextException)2 GCMBlockCipher (org.bouncycastle.crypto.modes.GCMBlockCipher)2 Hasher (io.nem.symbol.core.crypto.Hasher)1 Signature (io.nem.symbol.core.crypto.Signature)1 Ed25519EncodedFieldElement (io.nem.symbol.core.crypto.ed25519.arithmetic.Ed25519EncodedFieldElement)1 Ed25519EncodedGroupElement (io.nem.symbol.core.crypto.ed25519.arithmetic.Ed25519EncodedGroupElement)1 Ed25519GroupElement (io.nem.symbol.core.crypto.ed25519.arithmetic.Ed25519GroupElement)1