Search in sources :

Example 1 with InfoHash

use of com.acgist.snail.pojo.bean.InfoHash in project snail by acgist.

the class MSECipherTest method testCosted.

@Test
void testCosted() throws NetException {
    final byte[] secret = ArrayUtils.random(16);
    final InfoHash infoHash = InfoHash.newInstance(ArrayUtils.random(20));
    final var sender = MSECipher.newSender(secret, infoHash);
    final var recver = MSECipher.newRecver(secret, infoHash);
    final byte[] data = ArrayUtils.random(20);
    final long costed = this.costed(100000, () -> {
        try {
            final byte[] senderEncryptData = sender.encrypt(data);
            final byte[] recverDecryptData = recver.decrypt(senderEncryptData);
            if (recverDecryptData == null) {
                LOGGER.warn("解密失败");
            }
        } catch (NetException e) {
            LOGGER.error("数据加解密异常", e);
        }
    });
    assertTrue(costed < 1000);
}
Also used : InfoHash(com.acgist.snail.pojo.bean.InfoHash) NetException(com.acgist.snail.context.exception.NetException) Test(org.junit.jupiter.api.Test)

Example 2 with InfoHash

use of com.acgist.snail.pojo.bean.InfoHash in project snail by acgist.

the class MSECipherTest method testMSECipherEquals.

@Test
void testMSECipherEquals() throws NetException {
    final byte[] secret = ArrayUtils.random(16);
    final InfoHash infoHash = InfoHash.newInstance(ArrayUtils.random(20));
    final var sender = MSECipher.newSender(secret, infoHash);
    final var recver = MSECipher.newRecver(secret, infoHash);
    final byte[] data = ArrayUtils.random(20);
    assertArrayEquals(sender.decrypt(data), recver.encrypt(data));
    assertArrayEquals(sender.encrypt(data), recver.decrypt(data));
}
Also used : InfoHash(com.acgist.snail.pojo.bean.InfoHash) Test(org.junit.jupiter.api.Test)

Example 3 with InfoHash

use of com.acgist.snail.pojo.bean.InfoHash in project snail by acgist.

the class MSECipherTest method testMSECipher.

@Test
void testMSECipher() throws NetException {
    final byte[] secret = ArrayUtils.random(16);
    final InfoHash infoHash = InfoHash.newInstance(ArrayUtils.random(20));
    final var sender = MSECipher.newSender(secret, infoHash);
    final var recver = MSECipher.newRecver(secret, infoHash);
    final byte[] data = ArrayUtils.random(20);
    final byte[] senderEncryptData = sender.encrypt(data);
    final byte[] recverDecryptData = recver.decrypt(senderEncryptData);
    this.log(data);
    this.log(senderEncryptData);
    this.log(recverDecryptData);
    assertArrayEquals(data, recverDecryptData);
    final byte[] recverEncryptData = recver.encrypt(data);
    final byte[] senderDecryptData = sender.decrypt(recverEncryptData);
    this.log(recverEncryptData);
    this.log(senderDecryptData);
    assertArrayEquals(data, senderDecryptData);
}
Also used : InfoHash(com.acgist.snail.pojo.bean.InfoHash) Test(org.junit.jupiter.api.Test)

Aggregations

InfoHash (com.acgist.snail.pojo.bean.InfoHash)3 Test (org.junit.jupiter.api.Test)3 NetException (com.acgist.snail.context.exception.NetException)1