code cleanup
This commit is contained in:
parent
e346434042
commit
a532a9c262
@ -1,106 +0,0 @@
|
|||||||
|
|
||||||
- Copyright (c) 2010 and beyond, dorkbox llc. All rights reserved.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|
||||||
|
|
||||||
THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS
|
|
||||||
ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
|
|
||||||
PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
|
|
||||||
NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
|
|
||||||
SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE SOFTWARE
|
|
||||||
COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR
|
|
||||||
ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- BinarySearch - MIT License
|
|
||||||
https://github.com/timboudreau/util
|
|
||||||
Copyright 2013 Tim Boudreau
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- BouncyCastle - MIT X11 License
|
|
||||||
http://www.bouncycastle.org
|
|
||||||
Copyright 2000 - 2009 The Legion Of The Bouncy Castle
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- ConcurrentHashMapV8 - CC0 License
|
|
||||||
Written by Doug Lea with assistance from members of JCP JSR-166
|
|
||||||
Expert Group and released to the public domain, as explained at
|
|
||||||
http://creativecommons.org/publicdomain/zero/1.0/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- FastObjectPool - Apache 2.0 License
|
|
||||||
http://ashkrit.blogspot.com/2013/05/lock-less-java-object-pool.html
|
|
||||||
https://github.com/ashkrit/blog/tree/master/FastObjectPool
|
|
||||||
Copyright 2013 Ashkrit
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- FilenameUtils.java (normalize + dependencies) - Apache 2.0 License
|
|
||||||
http://commons.apache.org/proper/commons-io/
|
|
||||||
Copyright 2013 ASF
|
|
||||||
Authors: Kevin A. Burton, Scott Sanders, Daniel Rall, Christoph.Reck,
|
|
||||||
Peter Donald, Jeff Turner, Matthew Hawthorne, Martin Cooper,
|
|
||||||
Jeremias Maerki, Stephen Colebourne
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- JNA - Apache 2.0 License
|
|
||||||
https://github.com/twall/jna
|
|
||||||
Copyright (c) 2011 Timothy Wall
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- jOOU, Unsigned Numbers for Java - Apache 2.0 License
|
|
||||||
https://github.com/jOOQ/jOOU/tree/master/jOOU
|
|
||||||
Copyright 2011-2013, Lukas Eder, lukas.eder@gmail.com
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- Kryo - New BSD License
|
|
||||||
https://github.com/EsotericSoftware/kryo
|
|
||||||
Copyright 2008, Nathan Sweet, All rights reserved.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- LAN HostDiscovery from Apache Commons JCS - Apache 2.0 License
|
|
||||||
https://issues.apache.org/jira/browse/JCS-40
|
|
||||||
Copyright 2001-2014 The Apache Software Foundation.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- MathUtils, IntArray, IntMap - Apache 2.0 License
|
|
||||||
http://github.com/libgdx/libgdx/
|
|
||||||
Copyright 2013
|
|
||||||
Mario Zechner <badlogicgames@gmail.com>
|
|
||||||
Nathan Sweet <nathan.sweet@gmail.com>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- MersenneTwisterFast, v20 - BSD License
|
|
||||||
http://www.cs.gmu.edu/~sean/research/mersenne/MersenneTwisterFast.java
|
|
||||||
Copyright 2003 by Sean Luke
|
|
||||||
Portions copyright 1993 by Michael Lecuyer
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- migbase64 - High performance base64 encoder & decoder - BSD License
|
|
||||||
http://migbase64.sourceforge.net/
|
|
||||||
Copyright 2004, Mikael Grev, MiG InfoCom AB. (base64@miginfocom.com)
|
|
||||||
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
||||||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
|
|
||||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
|
||||||
<listEntry value="/Dorkbox-Util"/>
|
|
||||||
</listAttribute>
|
|
||||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
|
||||||
<listEntry value="4"/>
|
|
||||||
</listAttribute>
|
|
||||||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=Dorkbox-Util"/>
|
|
||||||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
|
|
||||||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
|
|
||||||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
|
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
|
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Dorkbox-Util"/>
|
|
||||||
</launchConfiguration>
|
|
File diff suppressed because it is too large
Load Diff
@ -44,7 +44,7 @@ import java.util.zip.InflaterInputStream;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public
|
public
|
||||||
class StorageBase {
|
class StorageBase {
|
||||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
private final Logger logger = LoggerFactory.getLogger(getClass().getSimpleName());
|
||||||
|
|
||||||
|
|
||||||
// File pointer to the data start pointer header.
|
// File pointer to the data start pointer header.
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
|
|
||||||
package dorkbox.util.crypto;
|
package dorkbox.util.crypto;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import dorkbox.util.crypto.bouncycastle.GCMBlockCipher_ByteBuf;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bouncycastle.crypto.engines.AESFastEngine;
|
import org.bouncycastle.crypto.engines.AESFastEngine;
|
||||||
import org.bouncycastle.crypto.modes.GCMBlockCipher;
|
import org.bouncycastle.crypto.modes.GCMBlockCipher;
|
||||||
import org.bouncycastle.crypto.params.KeyParameter;
|
import org.bouncycastle.crypto.params.KeyParameter;
|
||||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import dorkbox.util.crypto.bouncycastle.GCMBlockCipher_ByteBuf;
|
import java.io.IOException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class AesByteBufTest {
|
public class AesByteBufTest {
|
||||||
|
|
||||||
|
org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass());
|
||||||
private static String entropySeed = "asdjhasdkljalksdfhlaks4356268909087s0dfgkjh255124515hasdg87";
|
private static String entropySeed = "asdjhasdkljalksdfhlaks4356268909087s0dfgkjh255124515hasdg87";
|
||||||
|
|
||||||
private String text = "hello, my name is inigo montoya. hello, my name is inigo montoya. hello, my name is inigo montoya." +
|
private String text = "hello, my name is inigo montoya. hello, my name is inigo montoya. hello, my name is inigo montoya." +
|
||||||
@ -67,12 +67,12 @@ public class AesByteBufTest {
|
|||||||
ByteBuf source = Unpooled.wrappedBuffer(SOURCE);
|
ByteBuf source = Unpooled.wrappedBuffer(SOURCE);
|
||||||
int length = SOURCE.length;
|
int length = SOURCE.length;
|
||||||
ByteBuf encryptAES = Unpooled.buffer(1024);
|
ByteBuf encryptAES = Unpooled.buffer(1024);
|
||||||
int encryptLength = Crypto.AES.encrypt(aesEngine1, aesIVAndKey, source, encryptAES, length);
|
int encryptLength = Crypto.AES.encrypt(aesEngine1, aesIVAndKey, source, encryptAES, length, logger);
|
||||||
|
|
||||||
byte[] encrypt = new byte[encryptLength];
|
byte[] encrypt = new byte[encryptLength];
|
||||||
System.arraycopy(encryptAES.array(), 0, encrypt, 0, encryptLength);
|
System.arraycopy(encryptAES.array(), 0, encrypt, 0, encryptLength);
|
||||||
|
|
||||||
byte[] encrypt2 = Crypto.AES.encrypt(aesEngine2, key, iv, SOURCE);
|
byte[] encrypt2 = Crypto.AES.encrypt(aesEngine2, key, iv, SOURCE, logger);
|
||||||
|
|
||||||
|
|
||||||
if (Arrays.equals(SOURCE, encrypt)) {
|
if (Arrays.equals(SOURCE, encrypt)) {
|
||||||
@ -105,13 +105,13 @@ public class AesByteBufTest {
|
|||||||
ByteBuf source = Unpooled.wrappedBuffer(SOURCE);
|
ByteBuf source = Unpooled.wrappedBuffer(SOURCE);
|
||||||
int length = SOURCE.length;
|
int length = SOURCE.length;
|
||||||
ByteBuf encryptAES = Unpooled.buffer(1024);
|
ByteBuf encryptAES = Unpooled.buffer(1024);
|
||||||
int encryptLength = Crypto.AES.encrypt(aesEngine1, aesIVAndKey, source, encryptAES, length);
|
int encryptLength = Crypto.AES.encrypt(aesEngine1, aesIVAndKey, source, encryptAES, length, logger);
|
||||||
|
|
||||||
byte[] encrypt = new byte[encryptLength];
|
byte[] encrypt = new byte[encryptLength];
|
||||||
System.arraycopy(encryptAES.array(), 0, encrypt, 0, encryptLength);
|
System.arraycopy(encryptAES.array(), 0, encrypt, 0, encryptLength);
|
||||||
|
|
||||||
|
|
||||||
byte[] encrypt2 = Crypto.AES.encrypt(aesEngine2, key, iv, SOURCE);
|
byte[] encrypt2 = Crypto.AES.encrypt(aesEngine2, key, iv, SOURCE, logger);
|
||||||
|
|
||||||
|
|
||||||
if (Arrays.equals(SOURCE, encrypt)) {
|
if (Arrays.equals(SOURCE, encrypt)) {
|
||||||
@ -142,13 +142,13 @@ public class AesByteBufTest {
|
|||||||
ByteBuf source = Unpooled.wrappedBuffer(bytes);
|
ByteBuf source = Unpooled.wrappedBuffer(bytes);
|
||||||
int length = bytes.length;
|
int length = bytes.length;
|
||||||
ByteBuf encryptAES = Unpooled.buffer(1024);
|
ByteBuf encryptAES = Unpooled.buffer(1024);
|
||||||
int encryptLength = Crypto.AES.encrypt(aesEngine1, aesIVAndKey, source, encryptAES, length);
|
int encryptLength = Crypto.AES.encrypt(aesEngine1, aesIVAndKey, source, encryptAES, length, logger);
|
||||||
|
|
||||||
byte[] encrypt = new byte[encryptLength];
|
byte[] encrypt = new byte[encryptLength];
|
||||||
System.arraycopy(encryptAES.array(), 0, encrypt, 0, encryptLength);
|
System.arraycopy(encryptAES.array(), 0, encrypt, 0, encryptLength);
|
||||||
|
|
||||||
|
|
||||||
byte[] decrypt = Crypto.AES.decrypt(aesEngine2, key, iv, encrypt);
|
byte[] decrypt = Crypto.AES.decrypt(aesEngine2, key, iv, encrypt, logger);
|
||||||
|
|
||||||
|
|
||||||
if (Arrays.equals(bytes, encrypt)) {
|
if (Arrays.equals(bytes, encrypt)) {
|
||||||
@ -177,16 +177,16 @@ public class AesByteBufTest {
|
|||||||
rand.nextBytes(key); // 256bit key (32 bytes)
|
rand.nextBytes(key); // 256bit key (32 bytes)
|
||||||
rand.nextBytes(iv); // 128bit block size (16 bytes)
|
rand.nextBytes(iv); // 128bit block size (16 bytes)
|
||||||
|
|
||||||
final byte[] encrypt = Crypto.AES.encrypt(aesEngine1, key, iv, SOURCE);
|
final byte[] encrypt = Crypto.AES.encrypt(aesEngine1, key, iv, SOURCE, logger);
|
||||||
final ByteBuf encryptAES = Unpooled.wrappedBuffer(encrypt);
|
final ByteBuf encryptAES = Unpooled.wrappedBuffer(encrypt);
|
||||||
final int length = encrypt.length;
|
final int length = encrypt.length;
|
||||||
|
|
||||||
byte[] decrypt1 = Crypto.AES.decrypt(aesEngine1, key, iv, encrypt);
|
byte[] decrypt1 = Crypto.AES.decrypt(aesEngine1, key, iv, encrypt, logger);
|
||||||
|
|
||||||
|
|
||||||
ParametersWithIV aesIVAndKey = new ParametersWithIV(new KeyParameter(key), iv);
|
ParametersWithIV aesIVAndKey = new ParametersWithIV(new KeyParameter(key), iv);
|
||||||
ByteBuf decryptAES = Unpooled.buffer(1024);
|
ByteBuf decryptAES = Unpooled.buffer(1024);
|
||||||
int decryptLength = Crypto.AES.decrypt(aesEngine2, aesIVAndKey, encryptAES, decryptAES, length);
|
int decryptLength = Crypto.AES.decrypt(aesEngine2, aesIVAndKey, encryptAES, decryptAES, length, logger);
|
||||||
byte[] decrypt2 = new byte[decryptLength];
|
byte[] decrypt2 = new byte[decryptLength];
|
||||||
System.arraycopy(decryptAES.array(), 0, decrypt2, 0, decryptLength);
|
System.arraycopy(decryptAES.array(), 0, decrypt2, 0, decryptLength);
|
||||||
|
|
||||||
@ -221,17 +221,17 @@ public class AesByteBufTest {
|
|||||||
rand.nextBytes(key); // 256bit key (32 bytes)
|
rand.nextBytes(key); // 256bit key (32 bytes)
|
||||||
rand.nextBytes(iv); // 128bit block size (16 bytes)
|
rand.nextBytes(iv); // 128bit block size (16 bytes)
|
||||||
|
|
||||||
final byte[] encrypt = Crypto.AES.encrypt(aesEngine1, key, iv, SOURCE);
|
final byte[] encrypt = Crypto.AES.encrypt(aesEngine1, key, iv, SOURCE, logger);
|
||||||
final ByteBuf encryptAES = Unpooled.wrappedBuffer(encrypt);
|
final ByteBuf encryptAES = Unpooled.wrappedBuffer(encrypt);
|
||||||
final int length = encrypt.length;
|
final int length = encrypt.length;
|
||||||
|
|
||||||
|
|
||||||
byte[] decrypt1 = Crypto.AES.decrypt(aesEngine1, key, iv, encrypt);
|
byte[] decrypt1 = Crypto.AES.decrypt(aesEngine1, key, iv, encrypt, logger);
|
||||||
|
|
||||||
|
|
||||||
ParametersWithIV aesIVAndKey = new ParametersWithIV(new KeyParameter(key), iv);
|
ParametersWithIV aesIVAndKey = new ParametersWithIV(new KeyParameter(key), iv);
|
||||||
ByteBuf decryptAES = Unpooled.buffer(1024);
|
ByteBuf decryptAES = Unpooled.buffer(1024);
|
||||||
int decryptLength = Crypto.AES.decrypt(aesEngine2, aesIVAndKey, encryptAES, decryptAES, length);
|
int decryptLength = Crypto.AES.decrypt(aesEngine2, aesIVAndKey, encryptAES, decryptAES, length, logger);
|
||||||
byte[] decrypt2 = new byte[decryptLength];
|
byte[] decrypt2 = new byte[decryptLength];
|
||||||
System.arraycopy(decryptAES.array(), 0, decrypt2, 0, decryptLength);
|
System.arraycopy(decryptAES.array(), 0, decrypt2, 0, decryptLength);
|
||||||
|
|
||||||
@ -266,14 +266,14 @@ public class AesByteBufTest {
|
|||||||
rand.nextBytes(iv); // 128bit block size (16 bytes)
|
rand.nextBytes(iv); // 128bit block size (16 bytes)
|
||||||
|
|
||||||
|
|
||||||
byte[] encrypt = Crypto.AES.encrypt(aesEngine1, key, iv, SOURCE);
|
byte[] encrypt = Crypto.AES.encrypt(aesEngine1, key, iv, SOURCE, logger);
|
||||||
ByteBuf encryptAES = Unpooled.wrappedBuffer(encrypt);
|
ByteBuf encryptAES = Unpooled.wrappedBuffer(encrypt);
|
||||||
int length = encrypt.length;
|
int length = encrypt.length;
|
||||||
|
|
||||||
|
|
||||||
ParametersWithIV aesIVAndKey = new ParametersWithIV(new KeyParameter(key), iv);
|
ParametersWithIV aesIVAndKey = new ParametersWithIV(new KeyParameter(key), iv);
|
||||||
ByteBuf decryptAES = Unpooled.buffer(1024);
|
ByteBuf decryptAES = Unpooled.buffer(1024);
|
||||||
int decryptLength = Crypto.AES.decrypt(aesEngine2, aesIVAndKey, encryptAES, decryptAES, length);
|
int decryptLength = Crypto.AES.decrypt(aesEngine2, aesIVAndKey, encryptAES, decryptAES, length, logger);
|
||||||
byte[] decrypt = new byte[decryptLength];
|
byte[] decrypt = new byte[decryptLength];
|
||||||
System.arraycopy(decryptAES.array(), 0, decrypt, 0, decryptLength);
|
System.arraycopy(decryptAES.array(), 0, decrypt, 0, decryptLength);
|
||||||
|
|
||||||
@ -303,14 +303,14 @@ public class AesByteBufTest {
|
|||||||
rand.nextBytes(iv); // 128bit block size (16 bytes)
|
rand.nextBytes(iv); // 128bit block size (16 bytes)
|
||||||
|
|
||||||
|
|
||||||
byte[] encrypt = Crypto.AES.encrypt(aesEngine1, key, iv, SOURCE);
|
byte[] encrypt = Crypto.AES.encrypt(aesEngine1, key, iv, SOURCE, logger);
|
||||||
ByteBuf encryptAES = Unpooled.wrappedBuffer(encrypt);
|
ByteBuf encryptAES = Unpooled.wrappedBuffer(encrypt);
|
||||||
int length = encrypt.length;
|
int length = encrypt.length;
|
||||||
|
|
||||||
|
|
||||||
ParametersWithIV aesIVAndKey = new ParametersWithIV(new KeyParameter(key), iv);
|
ParametersWithIV aesIVAndKey = new ParametersWithIV(new KeyParameter(key), iv);
|
||||||
ByteBuf decryptAES = Unpooled.buffer(1024);
|
ByteBuf decryptAES = Unpooled.buffer(1024);
|
||||||
int decryptLength = Crypto.AES.decrypt(aesEngine2, aesIVAndKey, encryptAES, decryptAES, length);
|
int decryptLength = Crypto.AES.decrypt(aesEngine2, aesIVAndKey, encryptAES, decryptAES, length, logger);
|
||||||
byte[] decrypt = new byte[decryptLength];
|
byte[] decrypt = new byte[decryptLength];
|
||||||
System.arraycopy(decryptAES.array(), 0, decrypt, 0, decryptLength);
|
System.arraycopy(decryptAES.array(), 0, decrypt, 0, decryptLength);
|
||||||
|
|
||||||
|
@ -2,22 +2,23 @@
|
|||||||
package dorkbox.util.crypto;
|
package dorkbox.util.crypto;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bouncycastle.crypto.engines.AESFastEngine;
|
import org.bouncycastle.crypto.engines.AESFastEngine;
|
||||||
import org.bouncycastle.crypto.modes.CBCBlockCipher;
|
import org.bouncycastle.crypto.modes.CBCBlockCipher;
|
||||||
import org.bouncycastle.crypto.modes.GCMBlockCipher;
|
import org.bouncycastle.crypto.modes.GCMBlockCipher;
|
||||||
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class AesTest {
|
public class AesTest {
|
||||||
|
|
||||||
|
org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass());
|
||||||
private static String entropySeed = "asdjhasdkljalksdfhlaks4356268909087s0dfgkjh255124515hasdg87";
|
private static String entropySeed = "asdjhasdkljalksdfhlaks4356268909087s0dfgkjh255124515hasdg87";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -36,8 +37,8 @@ public class AesTest {
|
|||||||
rand.nextBytes(iv); // 128bit block size (16 bytes)
|
rand.nextBytes(iv); // 128bit block size (16 bytes)
|
||||||
|
|
||||||
|
|
||||||
byte[] encryptAES = Crypto.AES.encrypt(aesEngine, key, iv, bytes);
|
byte[] encryptAES = Crypto.AES.encrypt(aesEngine, key, iv, bytes, logger);
|
||||||
byte[] decryptAES = Crypto.AES.decrypt(aesEngine, key, iv, encryptAES);
|
byte[] decryptAES = Crypto.AES.decrypt(aesEngine, key, iv, encryptAES, logger);
|
||||||
|
|
||||||
if (Arrays.equals(bytes, encryptAES)) {
|
if (Arrays.equals(bytes, encryptAES)) {
|
||||||
fail("bytes should not be equal");
|
fail("bytes should not be equal");
|
||||||
@ -66,8 +67,8 @@ public class AesTest {
|
|||||||
rand.nextBytes(iv); // 16bit block size
|
rand.nextBytes(iv); // 16bit block size
|
||||||
|
|
||||||
|
|
||||||
byte[] encryptAES = Crypto.AES.encrypt(aesEngine, key, iv, bytes);
|
byte[] encryptAES = Crypto.AES.encrypt(aesEngine, key, iv, bytes, logger);
|
||||||
byte[] decryptAES = Crypto.AES.decrypt(aesEngine, key, iv, encryptAES);
|
byte[] decryptAES = Crypto.AES.decrypt(aesEngine, key, iv, encryptAES, logger);
|
||||||
|
|
||||||
if (Arrays.equals(bytes, encryptAES)) {
|
if (Arrays.equals(bytes, encryptAES)) {
|
||||||
fail("bytes should not be equal");
|
fail("bytes should not be equal");
|
||||||
@ -96,7 +97,7 @@ public class AesTest {
|
|||||||
rand.nextBytes(iv); // 128bit block size
|
rand.nextBytes(iv); // 128bit block size
|
||||||
|
|
||||||
|
|
||||||
boolean success = Crypto.AES.encryptStream(aesEngine, key, iv, inputStream, outputStream);
|
boolean success = Crypto.AES.encryptStream(aesEngine, key, iv, inputStream, outputStream, logger);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
fail("crypto was not successful");
|
fail("crypto was not successful");
|
||||||
@ -107,7 +108,7 @@ public class AesTest {
|
|||||||
inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
outputStream = new ByteArrayOutputStream();
|
outputStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
success = Crypto.AES.decryptStream(aesEngine, key, iv, inputStream, outputStream);
|
success = Crypto.AES.decryptStream(aesEngine, key, iv, inputStream, outputStream, logger);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
fail("crypto was not successful");
|
fail("crypto was not successful");
|
||||||
@ -144,7 +145,7 @@ public class AesTest {
|
|||||||
rand.nextBytes(iv); // 128bit block size
|
rand.nextBytes(iv); // 128bit block size
|
||||||
|
|
||||||
|
|
||||||
boolean success = Crypto.AES.encryptStream(aesEngine, key, iv, inputStream, outputStream);
|
boolean success = Crypto.AES.encryptStream(aesEngine, key, iv, inputStream, outputStream, logger);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
fail("crypto was not successful");
|
fail("crypto was not successful");
|
||||||
@ -155,7 +156,7 @@ public class AesTest {
|
|||||||
inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
outputStream = new ByteArrayOutputStream();
|
outputStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
success = Crypto.AES.decryptStream(aesEngine, key, iv, inputStream, outputStream);
|
success = Crypto.AES.decryptStream(aesEngine, key, iv, inputStream, outputStream, logger);
|
||||||
|
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
@ -189,8 +190,8 @@ public class AesTest {
|
|||||||
rand.nextBytes(iv);
|
rand.nextBytes(iv);
|
||||||
|
|
||||||
|
|
||||||
byte[] encryptAES = Crypto.AES.encryptWithIV(aesEngine, key, iv, bytes);
|
byte[] encryptAES = Crypto.AES.encryptWithIV(aesEngine, key, iv, bytes, logger);
|
||||||
byte[] decryptAES = Crypto.AES.decryptWithIV(aesEngine, key, encryptAES);
|
byte[] decryptAES = Crypto.AES.decryptWithIV(aesEngine, key, encryptAES, logger);
|
||||||
|
|
||||||
if (Arrays.equals(bytes, encryptAES)) {
|
if (Arrays.equals(bytes, encryptAES)) {
|
||||||
fail("bytes should not be equal");
|
fail("bytes should not be equal");
|
||||||
@ -219,8 +220,8 @@ public class AesTest {
|
|||||||
rand.nextBytes(iv);
|
rand.nextBytes(iv);
|
||||||
|
|
||||||
|
|
||||||
byte[] encryptAES = Crypto.AES.encryptWithIV(aesEngine, key, iv, bytes);
|
byte[] encryptAES = Crypto.AES.encryptWithIV(aesEngine, key, iv, bytes, logger);
|
||||||
byte[] decryptAES = Crypto.AES.decryptWithIV(aesEngine, key, encryptAES);
|
byte[] decryptAES = Crypto.AES.decryptWithIV(aesEngine, key, encryptAES, logger);
|
||||||
|
|
||||||
if (Arrays.equals(bytes, encryptAES)) {
|
if (Arrays.equals(bytes, encryptAES)) {
|
||||||
fail("bytes should not be equal");
|
fail("bytes should not be equal");
|
||||||
@ -249,7 +250,7 @@ public class AesTest {
|
|||||||
rand.nextBytes(iv); // 128bit block size
|
rand.nextBytes(iv); // 128bit block size
|
||||||
|
|
||||||
|
|
||||||
boolean success = Crypto.AES.encryptStreamWithIV(aesEngine, key, iv, inputStream, outputStream);
|
boolean success = Crypto.AES.encryptStreamWithIV(aesEngine, key, iv, inputStream, outputStream, logger);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
fail("crypto was not successful");
|
fail("crypto was not successful");
|
||||||
@ -260,7 +261,7 @@ public class AesTest {
|
|||||||
inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
outputStream = new ByteArrayOutputStream();
|
outputStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
success = Crypto.AES.decryptStreamWithIV(aesEngine, key, inputStream, outputStream);
|
success = Crypto.AES.decryptStreamWithIV(aesEngine, key, inputStream, outputStream, logger);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
fail("crypto was not successful");
|
fail("crypto was not successful");
|
||||||
@ -297,7 +298,7 @@ public class AesTest {
|
|||||||
rand.nextBytes(iv); // 128bit block size
|
rand.nextBytes(iv); // 128bit block size
|
||||||
|
|
||||||
|
|
||||||
boolean success = Crypto.AES.encryptStreamWithIV(aesEngine, key, iv, inputStream, outputStream);
|
boolean success = Crypto.AES.encryptStreamWithIV(aesEngine, key, iv, inputStream, outputStream, logger);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
fail("crypto was not successful");
|
fail("crypto was not successful");
|
||||||
@ -308,7 +309,7 @@ public class AesTest {
|
|||||||
inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
outputStream = new ByteArrayOutputStream();
|
outputStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
success = Crypto.AES.decryptStreamWithIV(aesEngine, key, inputStream, outputStream);
|
success = Crypto.AES.decryptStreamWithIV(aesEngine, key, inputStream, outputStream, logger);
|
||||||
|
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
@ -2,15 +2,13 @@
|
|||||||
package dorkbox.util.crypto;
|
package dorkbox.util.crypto;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import com.esotericsoftware.kryo.Kryo;
|
||||||
|
import com.esotericsoftware.kryo.io.Input;
|
||||||
import java.io.ByteArrayInputStream;
|
import com.esotericsoftware.kryo.io.Output;
|
||||||
import java.io.ByteArrayOutputStream;
|
import dorkbox.util.serialization.EccPrivateKeySerializer;
|
||||||
import java.io.IOException;
|
import dorkbox.util.serialization.EccPublicKeySerializer;
|
||||||
import java.math.BigInteger;
|
import dorkbox.util.serialization.IesParametersSerializer;
|
||||||
import java.security.SecureRandom;
|
import dorkbox.util.serialization.IesWithCipherParametersSerializer;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
||||||
import org.bouncycastle.crypto.BasicAgreement;
|
import org.bouncycastle.crypto.BasicAgreement;
|
||||||
import org.bouncycastle.crypto.CipherParameters;
|
import org.bouncycastle.crypto.CipherParameters;
|
||||||
@ -19,11 +17,7 @@ import org.bouncycastle.crypto.engines.AESFastEngine;
|
|||||||
import org.bouncycastle.crypto.engines.IESEngine;
|
import org.bouncycastle.crypto.engines.IESEngine;
|
||||||
import org.bouncycastle.crypto.modes.CBCBlockCipher;
|
import org.bouncycastle.crypto.modes.CBCBlockCipher;
|
||||||
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
||||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
import org.bouncycastle.crypto.params.*;
|
||||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
|
||||||
import org.bouncycastle.crypto.params.IESParameters;
|
|
||||||
import org.bouncycastle.crypto.params.IESWithCipherParameters;
|
|
||||||
import org.bouncycastle.crypto.params.ParametersWithRandom;
|
|
||||||
import org.bouncycastle.crypto.signers.ECDSASigner;
|
import org.bouncycastle.crypto.signers.ECDSASigner;
|
||||||
import org.bouncycastle.crypto.util.PrivateKeyFactory;
|
import org.bouncycastle.crypto.util.PrivateKeyFactory;
|
||||||
import org.bouncycastle.crypto.util.PublicKeyFactory;
|
import org.bouncycastle.crypto.util.PublicKeyFactory;
|
||||||
@ -34,18 +28,19 @@ import org.bouncycastle.jce.spec.ECParameterSpec;
|
|||||||
import org.bouncycastle.util.encoders.Hex;
|
import org.bouncycastle.util.encoders.Hex;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.esotericsoftware.kryo.Kryo;
|
import java.io.ByteArrayInputStream;
|
||||||
import com.esotericsoftware.kryo.io.Input;
|
import java.io.ByteArrayOutputStream;
|
||||||
import com.esotericsoftware.kryo.io.Output;
|
import java.io.IOException;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import dorkbox.util.serialization.EccPrivateKeySerializer;
|
import static org.junit.Assert.fail;
|
||||||
import dorkbox.util.serialization.EccPublicKeySerializer;
|
|
||||||
import dorkbox.util.serialization.IesParametersSerializer;
|
|
||||||
import dorkbox.util.serialization.IesWithCipherParametersSerializer;
|
|
||||||
|
|
||||||
|
|
||||||
public class EccTest {
|
public class EccTest {
|
||||||
|
|
||||||
|
org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass());
|
||||||
private static String entropySeed = "asdjhaffasttjasdasdgfgaerym0698768.,./8909087s0dfgkjgb49bmngrSGDSG#";
|
private static String entropySeed = "asdjhaffasttjasdasdgfgaerym0698768.,./8909087s0dfgkjgb49bmngrSGDSG#";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -69,11 +64,13 @@ public class EccTest {
|
|||||||
CipherParameters private2 = key2.getPrivate();
|
CipherParameters private2 = key2.getPrivate();
|
||||||
CipherParameters public2 = key2.getPublic();
|
CipherParameters public2 = key2.getPublic();
|
||||||
|
|
||||||
byte[] message = Hex.decode("123456784358754934597967249867359283792374987692348750276509765091834790abcdef123456784358754934597967249867359283792374987692348750276509765091834790abcdef123456784358754934597967249867359283792374987692348750276509765091834790abcdef");
|
byte[] message = Hex.decode(
|
||||||
|
"123456784358754934597967249867359283792374987692348750276509765091834790abcdef123456784358754934597967249867359283792374987692348750276509765091834790abcdef123456784358754934597967249867359283792374987692348750276509765091834790abcdef");
|
||||||
|
|
||||||
|
|
||||||
// test stream mode
|
// test stream mode
|
||||||
byte[] encrypted = Crypto.ECC.encrypt(encrypt, private1, public2, cipherParams, message);
|
byte[] encrypted = Crypto.ECC.encrypt(encrypt, private1, public2, cipherParams, message, logger);
|
||||||
byte[] plaintext = Crypto.ECC.decrypt(decrypt, private2, public1, cipherParams, encrypted);
|
byte[] plaintext = Crypto.ECC.decrypt(decrypt, private2, public1, cipherParams, encrypted, logger);
|
||||||
|
|
||||||
if (Arrays.equals(encrypted, message)) {
|
if (Arrays.equals(encrypted, message)) {
|
||||||
fail("stream cipher test failed");
|
fail("stream cipher test failed");
|
||||||
@ -114,8 +111,8 @@ public class EccTest {
|
|||||||
byte[] message = Hex.decode("123456784358754934597967249867359283792374987692348750276509765091834790abcdef123456784358754934597967249867359283792374987692348750276509765091834790abcdef123456784358754934597967249867359283792374987692348750276509765091834790abcdef");
|
byte[] message = Hex.decode("123456784358754934597967249867359283792374987692348750276509765091834790abcdef123456784358754934597967249867359283792374987692348750276509765091834790abcdef123456784358754934597967249867359283792374987692348750276509765091834790abcdef");
|
||||||
|
|
||||||
// test stream mode
|
// test stream mode
|
||||||
byte[] encrypted = Crypto.ECC.encrypt(encrypt, private1, public2, cipherParams, message);
|
byte[] encrypted = Crypto.ECC.encrypt(encrypt, private1, public2, cipherParams, message, logger);
|
||||||
byte[] plaintext = Crypto.ECC.decrypt(decrypt, private2, public1, cipherParams, encrypted);
|
byte[] plaintext = Crypto.ECC.decrypt(decrypt, private2, public1, cipherParams, encrypted, logger);
|
||||||
|
|
||||||
if (Arrays.equals(encrypted, message)) {
|
if (Arrays.equals(encrypted, message)) {
|
||||||
fail("stream cipher test failed");
|
fail("stream cipher test failed");
|
||||||
|
@ -2,15 +2,11 @@
|
|||||||
package dorkbox.util.crypto;
|
package dorkbox.util.crypto;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import com.esotericsoftware.kryo.Kryo;
|
||||||
|
import com.esotericsoftware.kryo.io.Input;
|
||||||
import java.io.ByteArrayInputStream;
|
import com.esotericsoftware.kryo.io.Output;
|
||||||
import java.io.ByteArrayOutputStream;
|
import dorkbox.util.serialization.RsaPrivateKeySerializer;
|
||||||
import java.io.IOException;
|
import dorkbox.util.serialization.RsaPublicKeySerializer;
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
||||||
import org.bouncycastle.crypto.digests.SHA1Digest;
|
import org.bouncycastle.crypto.digests.SHA1Digest;
|
||||||
import org.bouncycastle.crypto.encodings.OAEPEncoding;
|
import org.bouncycastle.crypto.encodings.OAEPEncoding;
|
||||||
@ -22,15 +18,18 @@ import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters;
|
|||||||
import org.bouncycastle.crypto.signers.PSSSigner;
|
import org.bouncycastle.crypto.signers.PSSSigner;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.esotericsoftware.kryo.Kryo;
|
import java.io.ByteArrayInputStream;
|
||||||
import com.esotericsoftware.kryo.io.Input;
|
import java.io.ByteArrayOutputStream;
|
||||||
import com.esotericsoftware.kryo.io.Output;
|
import java.io.IOException;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import dorkbox.util.serialization.RsaPrivateKeySerializer;
|
import static org.junit.Assert.fail;
|
||||||
import dorkbox.util.serialization.RsaPublicKeySerializer;
|
|
||||||
|
|
||||||
|
|
||||||
public class RsaTest {
|
public class RsaTest {
|
||||||
|
org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass());
|
||||||
private static String entropySeed = "asdjhaffasttjjhgpx600gn,-356268909087s0dfgkjh255124515hasdg87";
|
private static String entropySeed = "asdjhaffasttjjhgpx600gn,-356268909087s0dfgkjh255124515hasdg87";
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@ -49,8 +48,8 @@ public class RsaTest {
|
|||||||
OAEPEncoding rsaEngine = new OAEPEncoding(engine, digest);
|
OAEPEncoding rsaEngine = new OAEPEncoding(engine, digest);
|
||||||
|
|
||||||
// test encrypt/decrypt
|
// test encrypt/decrypt
|
||||||
byte[] encryptRSA = Crypto.RSA.encrypt(rsaEngine, public1, bytes);
|
byte[] encryptRSA = Crypto.RSA.encrypt(rsaEngine, public1, bytes, logger);
|
||||||
byte[] decryptRSA = Crypto.RSA.decrypt(rsaEngine, private1, encryptRSA);
|
byte[] decryptRSA = Crypto.RSA.decrypt(rsaEngine, private1, encryptRSA, logger);
|
||||||
|
|
||||||
if (Arrays.equals(bytes, encryptRSA)) {
|
if (Arrays.equals(bytes, encryptRSA)) {
|
||||||
fail("bytes should not be equal");
|
fail("bytes should not be equal");
|
||||||
@ -63,7 +62,7 @@ public class RsaTest {
|
|||||||
// test signing/verification
|
// test signing/verification
|
||||||
PSSSigner signer = new PSSSigner(engine, digest, digest.getDigestSize());
|
PSSSigner signer = new PSSSigner(engine, digest, digest.getDigestSize());
|
||||||
|
|
||||||
byte[] signatureRSA = Crypto.RSA.sign(signer, private1, bytes);
|
byte[] signatureRSA = Crypto.RSA.sign(signer, private1, bytes, logger);
|
||||||
boolean verify = Crypto.RSA.verify(signer, public1, signatureRSA, bytes);
|
boolean verify = Crypto.RSA.verify(signer, public1, signatureRSA, bytes);
|
||||||
|
|
||||||
if (!verify) {
|
if (!verify) {
|
||||||
|
Loading…
Reference in New Issue
Block a user