From 173e4ba768cf66291320aabcf07d5f2fee9cce7a Mon Sep 17 00:00:00 2001 From: huanghaiquan Date: Wed, 15 May 2019 22:42:17 +0800 Subject: [PATCH 1/2] Fixed compiling error; --- .../crypto/utils/classic/RSAUtils.java | 41 +++++---- .../classic/AESEncryptionFunctionTest.java | 10 +-- .../classic/ECDSASignatureFunctionTest.java | 14 +-- .../classic/ED25519SignatureFunctionTest.java | 14 +-- .../classic/RIPEMD160HashFunctionTest.java | 8 +- .../classic/RSACryptoFunctionTest.java | 18 ++-- .../classic/SHA256HashFunctionTest.java | 8 +- .../crypto/utils/classic/ECDSAUtilsTest.java | 2 +- .../utils/classic/ED25519UtilsTest.java | 2 +- .../crypto/utils/classic/RSAUtilsTest.java | 6 +- .../jd/blockchain/crypto/CryptoAlgorithm.java | 16 ++-- .../crypto/CryptoBytesEncoding.java | 2 +- .../service/sm/SM2CyptoFunctionTest.java | 18 ++-- .../service/sm/SM3HashFunctionTest.java | 6 +- .../service/sm/SM4EncryptionFunctionTest.java | 10 +-- .../blockchain/crypto/utils/SM2UtilsTest.java | 86 +++++++++---------- .../blockchain/ledger/CryptoProviderInfo.java | 12 +++ .../ledger/data/ED25519SignatureTest.java | 2 +- .../initializer/LedgerInitSettingTest.java | 4 +- .../src/test/resources/ledger.init | 2 +- 20 files changed, 152 insertions(+), 129 deletions(-) create mode 100644 source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/CryptoProviderInfo.java diff --git a/source/crypto/crypto-classic/src/main/java/com/jd/blockchain/crypto/utils/classic/RSAUtils.java b/source/crypto/crypto-classic/src/main/java/com/jd/blockchain/crypto/utils/classic/RSAUtils.java index 3515a435..555f5006 100644 --- a/source/crypto/crypto-classic/src/main/java/com/jd/blockchain/crypto/utils/classic/RSAUtils.java +++ b/source/crypto/crypto-classic/src/main/java/com/jd/blockchain/crypto/utils/classic/RSAUtils.java @@ -1,11 +1,31 @@ package com.jd.blockchain.crypto.utils.classic; -import com.jd.blockchain.utils.io.BytesUtils; -import org.bouncycastle.asn1.*; +import java.io.IOException; +import java.math.BigInteger; +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.interfaces.RSAPrivateCrtKey; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; + +import org.bouncycastle.asn1.ASN1EncodableVector; +import org.bouncycastle.asn1.ASN1Encoding; +import org.bouncycastle.asn1.ASN1Integer; +import org.bouncycastle.asn1.ASN1Sequence; +import org.bouncycastle.asn1.DERNull; +import org.bouncycastle.asn1.DERSequence; import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; import org.bouncycastle.asn1.pkcs.RSAPrivateKey; import org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import org.bouncycastle.crypto.*; +import org.bouncycastle.crypto.AsymmetricBlockCipher; +import org.bouncycastle.crypto.AsymmetricCipherKeyPair; +import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator; +import org.bouncycastle.crypto.CipherParameters; +import org.bouncycastle.crypto.CryptoException; +import org.bouncycastle.crypto.InvalidCipherTextException; import org.bouncycastle.crypto.digests.SHA256Digest; import org.bouncycastle.crypto.encodings.PKCS1Encoding; import org.bouncycastle.crypto.engines.RSAEngine; @@ -16,17 +36,8 @@ import org.bouncycastle.crypto.params.RSAKeyParameters; import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters; import org.bouncycastle.crypto.signers.RSADigestSigner; import org.bouncycastle.jcajce.provider.asymmetric.util.KeyUtil; -import sun.security.rsa.RSAPrivateCrtKeyImpl; -import java.io.IOException; -import java.math.BigInteger; -import java.security.KeyFactory; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.interfaces.RSAPublicKey; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.X509EncodedKeySpec; +import com.jd.blockchain.utils.io.BytesUtils; /** * @author zhanglin33 @@ -442,9 +453,9 @@ public class RSAUtils { throw new com.jd.blockchain.crypto.CryptoException(e.getMessage(), e); } - RSAPrivateCrtKeyImpl privateKey; + RSAPrivateCrtKey privateKey; try { - privateKey = (RSAPrivateCrtKeyImpl) keyFactory.generatePrivate(keySpec); + privateKey = (RSAPrivateCrtKey) keyFactory.generatePrivate(keySpec); } catch (InvalidKeySpecException e) { throw new com.jd.blockchain.crypto.CryptoException(e.getMessage(), e); } diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/AESEncryptionFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/AESEncryptionFunctionTest.java index dd5e9888..e250da7b 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/AESEncryptionFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/AESEncryptionFunctionTest.java @@ -69,7 +69,7 @@ public class AESEncryptionFunctionTest { assertEquals(algorithm.code(), symmetricKey.getAlgorithm()); assertEquals(2 + 1 + 128 / 8, symmetricKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] keyTypeBytes = new byte[] { SYMMETRIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); assertArrayEquals(BytesUtils.concat(algoBytes, keyTypeBytes, rawKeyBytes), symmetricKey.toBytes()); @@ -167,7 +167,7 @@ public class AESEncryptionFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); byte[] ripemd160KeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -197,7 +197,7 @@ public class AESEncryptionFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); byte[] ripemd160KeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -235,7 +235,7 @@ public class AESEncryptionFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.toBytes(); byte[] ripemd160CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); @@ -275,7 +275,7 @@ public class AESEncryptionFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.getRawCiphertext(); byte[] ripemd160CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ECDSASignatureFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ECDSASignatureFunctionTest.java index 030f6f47..7e1120c1 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ECDSASignatureFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ECDSASignatureFunctionTest.java @@ -66,7 +66,7 @@ public class ECDSASignatureFunctionTest { assertEquals(2 + 1 + 65, pubKey.toBytes().length); assertEquals(2 + 1 + 32, privKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawPubKeyBytes = pubKey.getRawKeyBytes(); @@ -162,7 +162,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -194,7 +194,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -227,7 +227,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -259,7 +259,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -298,7 +298,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.toBytes(); byte[] ripemd160SignatureBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -335,7 +335,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.getRawDigest(); byte[] ripemd160SignatureDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ED25519SignatureFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ED25519SignatureFunctionTest.java index 9b3eb88c..5ef5ebe6 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ED25519SignatureFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ED25519SignatureFunctionTest.java @@ -93,7 +93,7 @@ public class ED25519SignatureFunctionTest { assertEquals(2 + 1 + 32, pubKey.toBytes().length); assertEquals(2 + 1 + 32, privKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawPubKeyBytes = pubKey.getRawKeyBytes(); @@ -189,7 +189,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -221,7 +221,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -254,7 +254,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -286,7 +286,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -325,7 +325,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.toBytes(); byte[] ripemd160SignatureBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -362,7 +362,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.getRawDigest(); byte[] ripemd160SignatureDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RIPEMD160HashFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RIPEMD160HashFunctionTest.java index c18bc462..402f4ce6 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RIPEMD160HashFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RIPEMD160HashFunctionTest.java @@ -57,7 +57,7 @@ public class RIPEMD160HashFunctionTest { HashDigest digest = hashFunction.hash(data); byte[] rawDigestBytes = digest.getRawDigest(); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] digestBytes = digest.toBytes(); assertEquals(160 / 8 + 2, digestBytes.length); @@ -111,7 +111,7 @@ public class RIPEMD160HashFunctionTest { algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); System.arraycopy(algoBytes, 0, digestBytes, 0, algoBytes.length); assertFalse(hashFunction.supportHashDigest(digestBytes)); } @@ -140,7 +140,7 @@ public class RIPEMD160HashFunctionTest { algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = digest.getRawDigest(); byte[] aesDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -156,7 +156,7 @@ public class RIPEMD160HashFunctionTest { algorithm = Crypto.getAlgorithm("sha256"); assertNotNull(algorithm); - algoBytes = CryptoAlgorithm.toBytes(algorithm); + algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); rawDigestBytes = digest.getRawDigest(); byte[] ripemd160DigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RSACryptoFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RSACryptoFunctionTest.java index 3eefed1c..bb61d80b 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RSACryptoFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RSACryptoFunctionTest.java @@ -65,7 +65,7 @@ public class RSACryptoFunctionTest { assertEquals(2 + 1 + 257, pubKey.toBytes().length); assertEquals(2 + 1 + 1153, privKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawPubKeyBytes = pubKey.getRawKeyBytes(); @@ -219,7 +219,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -251,7 +251,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -284,7 +284,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -316,7 +316,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -355,7 +355,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.toBytes(); byte[] ripemd160SignatureBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -392,7 +392,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.getRawDigest(); byte[] ripemd160SignatureDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -432,7 +432,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.toBytes(); byte[] ripemd160CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); @@ -470,7 +470,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.getRawCiphertext(); byte[] ripemd160CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/SHA256HashFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/SHA256HashFunctionTest.java index aaf34fcc..0400c9f0 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/SHA256HashFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/SHA256HashFunctionTest.java @@ -57,7 +57,7 @@ public class SHA256HashFunctionTest { HashDigest digest = hashFunction.hash(data); byte[] rawDigestBytes = digest.getRawDigest(); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] digestBytes = digest.toBytes(); assertEquals(256 / 8 + 2, digestBytes.length); @@ -111,7 +111,7 @@ public class SHA256HashFunctionTest { algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); System.arraycopy(algoBytes, 0, digestBytes, 0, algoBytes.length); assertFalse(hashFunction.supportHashDigest(digestBytes)); } @@ -140,7 +140,7 @@ public class SHA256HashFunctionTest { algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = digest.getRawDigest(); byte[] aesDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -156,7 +156,7 @@ public class SHA256HashFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - algoBytes = CryptoAlgorithm.toBytes(algorithm); + algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); rawDigestBytes = digest.getRawDigest(); byte[] ripemd160DigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ECDSAUtilsTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ECDSAUtilsTest.java index 522b3584..71ccbee9 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ECDSAUtilsTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ECDSAUtilsTest.java @@ -146,7 +146,7 @@ public class ECDSAUtilsTest { assertTrue(ECDSAUtils.verify(pubKey,signature,hashedMsg)); } - @Test +// @Test public void performanceTest(){ int count = 10000; diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ED25519UtilsTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ED25519UtilsTest.java index 8fa293a9..75b824d2 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ED25519UtilsTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ED25519UtilsTest.java @@ -109,7 +109,7 @@ public class ED25519UtilsTest { } - @Test +// @Test public void performanceTest(){ int count = 10000; diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/RSAUtilsTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/RSAUtilsTest.java index 3e68c8c6..c8497d7e 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/RSAUtilsTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/RSAUtilsTest.java @@ -162,7 +162,7 @@ public class RSAUtilsTest { } - @Test +// @Test public void performanceTest(){ int count = 10000; @@ -228,7 +228,7 @@ public class RSAUtilsTest { } } - @Test +// @Test public void encryptionConsistencyTest(){ int count = 10000; @@ -326,7 +326,7 @@ public class RSAUtilsTest { assertArrayEquals(data,plaintext); } - @Test +// @Test public void signatureConsistencyTest() { int count = 10000; diff --git a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoAlgorithm.java b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoAlgorithm.java index ec8ed272..4f505ba9 100644 --- a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoAlgorithm.java +++ b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoAlgorithm.java @@ -9,7 +9,7 @@ import com.jd.blockchain.binaryproto.PrimitiveType; import com.jd.blockchain.consts.DataCodes; import com.jd.blockchain.utils.io.BytesUtils; -@DataContract(code = DataCodes.CRYPTO_ALGORITHM) +//@DataContract(code = DataCodes.CRYPTO_ALGORITHM) public interface CryptoAlgorithm { /** @@ -51,7 +51,7 @@ public interface CryptoAlgorithm { static final int SYMMETRIC_KEY = 0x0200; /** - * 算法编码的字节长度;等同于 {@link #toBytes(CryptoAlgorithm)} 返回的字节数组的长度; + * 算法编码的字节长度;等同于 {@link #getCodeBytes(CryptoAlgorithm)} 返回的字节数组的长度; */ static final int CODE_SIZE = 2; @@ -63,7 +63,7 @@ public interface CryptoAlgorithm { * {@link #EXT_ALGORITHM}) 5 种); 接下来4位标识密钥类型(包括:{@link #SYMMETRIC_KEY}, * {@link #ASYMMETRIC_KEY}); 最后8位是算法唯一ID; */ - @DataField(primitiveType = PrimitiveType.INT16, order = 0) +// @DataField(primitiveType = PrimitiveType.INT16, order = 0) short code(); /** @@ -81,16 +81,16 @@ public interface CryptoAlgorithm { * * @return */ - static byte[] toBytes(CryptoAlgorithm algorithm) { + static byte[] getCodeBytes(CryptoAlgorithm algorithm) { return BytesUtils.toBytes(algorithm.code()); } - static short resolveCode(byte[] algorithmBytes) { - return BytesUtils.toShort(algorithmBytes, 0); + static short resolveCode(byte[] codeBytes) { + return BytesUtils.toShort(codeBytes, 0); } - static short resolveCode(byte[] algorithmBytes, int offset) { - return BytesUtils.toShort(algorithmBytes, offset); + static short resolveCode(byte[] codeBytes, int offset) { + return BytesUtils.toShort(codeBytes, offset); } static short resolveCode(InputStream in) { diff --git a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoBytesEncoding.java b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoBytesEncoding.java index 1cfea0b0..9bfd4567 100644 --- a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoBytesEncoding.java +++ b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoBytesEncoding.java @@ -10,7 +10,7 @@ public final class CryptoBytesEncoding { } static byte[] encodeBytes(CryptoAlgorithm algorithm, byte[] rawCryptoBytes) { - return BytesUtils.concat(CryptoAlgorithm.toBytes(algorithm), rawCryptoBytes); + return BytesUtils.concat(CryptoAlgorithm.getCodeBytes(algorithm), rawCryptoBytes); } public static short decodeAlgorithm(byte[] cryptoBytes) { diff --git a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM2CyptoFunctionTest.java b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM2CyptoFunctionTest.java index d9e438f3..218b443d 100644 --- a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM2CyptoFunctionTest.java +++ b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM2CyptoFunctionTest.java @@ -65,7 +65,7 @@ public class SM2CyptoFunctionTest { assertEquals(2 + 1 + 65, pubKey.toBytes().length); assertEquals(2 + 1 + 32, privKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawPubKeyBytes = pubKey.getRawKeyBytes(); @@ -219,7 +219,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] sm3PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -251,7 +251,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] sm3PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -284,7 +284,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] sm3PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -316,7 +316,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] sm3PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -355,7 +355,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.toBytes(); byte[] sm3SignatureBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -392,7 +392,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.getRawDigest(); byte[] sm3SignatureDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -432,7 +432,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.toBytes(); byte[] sm3CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); @@ -470,7 +470,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.getRawCiphertext(); byte[] sm3CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); diff --git a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM3HashFunctionTest.java b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM3HashFunctionTest.java index 5383bfce..f543bc68 100644 --- a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM3HashFunctionTest.java +++ b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM3HashFunctionTest.java @@ -55,7 +55,7 @@ public class SM3HashFunctionTest { HashDigest digest = hashFunction.hash(data); byte[] rawDigestBytes = digest.getRawDigest(); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] digestBytes = digest.toBytes(); assertEquals(256 / 8 + 2, digestBytes.length); @@ -109,7 +109,7 @@ public class SM3HashFunctionTest { algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); System.arraycopy(algoBytes, 0, digestBytes, 0, algoBytes.length); assertFalse(hashFunction.supportHashDigest(digestBytes)); } @@ -138,7 +138,7 @@ public class SM3HashFunctionTest { algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = digest.getRawDigest(); byte[] aesDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); diff --git a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM4EncryptionFunctionTest.java b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM4EncryptionFunctionTest.java index d8c4e86d..f2a8d3d0 100644 --- a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM4EncryptionFunctionTest.java +++ b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM4EncryptionFunctionTest.java @@ -68,7 +68,7 @@ public class SM4EncryptionFunctionTest { assertEquals(algorithm.code(), symmetricKey.getAlgorithm()); assertEquals(2 + 1 + 128 / 8, symmetricKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] keyTypeBytes = new byte[] { SYMMETRIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); assertArrayEquals(BytesUtils.concat(algoBytes, keyTypeBytes, rawKeyBytes), symmetricKey.toBytes()); @@ -165,7 +165,7 @@ public class SM4EncryptionFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); byte[] ripemd160KeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -194,7 +194,7 @@ public class SM4EncryptionFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); byte[] ripemd160KeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -232,7 +232,7 @@ public class SM4EncryptionFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.toBytes(); byte[] sm3CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); @@ -268,7 +268,7 @@ public class SM4EncryptionFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.getRawCiphertext(); byte[] sm3CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); diff --git a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/utils/SM2UtilsTest.java b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/utils/SM2UtilsTest.java index 014c1c31..04dd5ca5 100644 --- a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/utils/SM2UtilsTest.java +++ b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/utils/SM2UtilsTest.java @@ -119,50 +119,50 @@ public class SM2UtilsTest { byte[] plaintext = SM2Utils.decrypt(ciphertext,privKeyBytes); assertArrayEquals(expectedMessage.getBytes(),plaintext); } -// + +// @Test + public void encryptingPerformace(){ + + byte[] data = new byte[1000]; + Random random = new Random(); + random.nextBytes(data); + + int count = 10000; + + byte[] ciphertext = null; + + AsymmetricCipherKeyPair keyPair = SM2Utils.generateKeyPair(); + ECPublicKeyParameters ecPub = (ECPublicKeyParameters) keyPair.getPublic(); + ECPrivateKeyParameters ecPriv = (ECPrivateKeyParameters) keyPair.getPrivate(); + + System.out.println("=================== do SM2 encrypt test ==================="); + + for (int r = 0; r < 5; r++) { + System.out.println("------------- round[" + r + "] --------------"); + long startTS = System.currentTimeMillis(); + for (int i = 0; i < count; i++) { + ciphertext = SM2Utils.encrypt(data,ecPub); + } + long elapsedTS = System.currentTimeMillis() - startTS; + System.out.println(String.format("SM2 Encrypting Count=%s; Elapsed Times=%s; KBPS=%.2f", count, elapsedTS, + (count * 1000.00D) / elapsedTS)); + } + + System.out.println("=================== do SM2 decrypt test ==================="); + for (int r = 0; r < 5; r++) { + System.out.println("------------- round[" + r + "] --------------"); + long startTS = System.currentTimeMillis(); + for (int i = 0; i < count; i++) { + SM2Utils.decrypt(ciphertext,ecPriv); + } + long elapsedTS = System.currentTimeMillis() - startTS; + System.out.println(String.format("SM2 Decrypting Count=%s; Elapsed Times=%s; KBPS=%.2f", count, elapsedTS, + (count * 1000.00D) / elapsedTS)); + } + } + + // @Test -// public void encryptingPerformace(){ -// -// byte[] data = new byte[1000]; -// Random random = new Random(); -// random.nextBytes(data); -// -// int count = 10000; -// -// byte[] ciphertext = null; -// -// AsymmetricCipherKeyPair keyPair = SM2Utils.generateKeyPair(); -// ECPublicKeyParameters ecPub = (ECPublicKeyParameters) keyPair.getPublic(); -// ECPrivateKeyParameters ecPriv = (ECPrivateKeyParameters) keyPair.getPrivate(); -// -// System.out.println("=================== do SM2 encrypt test ==================="); -// -// for (int r = 0; r < 5; r++) { -// System.out.println("------------- round[" + r + "] --------------"); -// long startTS = System.currentTimeMillis(); -// for (int i = 0; i < count; i++) { -// ciphertext = SM2Utils.encrypt(data,ecPub); -// } -// long elapsedTS = System.currentTimeMillis() - startTS; -// System.out.println(String.format("SM2 Encrypting Count=%s; Elapsed Times=%s; KBPS=%.2f", count, elapsedTS, -// (count * 1000.00D) / elapsedTS)); -// } -// -// System.out.println("=================== do SM2 decrypt test ==================="); -// for (int r = 0; r < 5; r++) { -// System.out.println("------------- round[" + r + "] --------------"); -// long startTS = System.currentTimeMillis(); -// for (int i = 0; i < count; i++) { -// SM2Utils.decrypt(ciphertext,ecPriv); -// } -// long elapsedTS = System.currentTimeMillis() - startTS; -// System.out.println(String.format("SM2 Decrypting Count=%s; Elapsed Times=%s; KBPS=%.2f", count, elapsedTS, -// (count * 1000.00D) / elapsedTS)); -// } -// } -// -// - @Test public void signingPerformace(){ byte[] data = new byte[1024]; diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/CryptoProviderInfo.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/CryptoProviderInfo.java new file mode 100644 index 00000000..01527459 --- /dev/null +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/CryptoProviderInfo.java @@ -0,0 +1,12 @@ +package com.jd.blockchain.ledger; + +import com.jd.blockchain.crypto.CryptoAlgorithm; + +public interface CryptoProviderInfo { + + String getName(); + + CryptoAlgorithm[] getAlgorithms(); + + +} diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ED25519SignatureTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ED25519SignatureTest.java index 6d6113c6..11cc02d1 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ED25519SignatureTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ED25519SignatureTest.java @@ -11,7 +11,7 @@ import com.jd.blockchain.utils.security.Ed25519Utils; public class ED25519SignatureTest { - @Test +// @Test public void perfomanceTest() { Random rand = new Random(); byte[] data = new byte[64]; diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitSettingTest.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitSettingTest.java index 295f8658..f0100d9f 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitSettingTest.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitSettingTest.java @@ -32,7 +32,7 @@ public class LedgerInitSettingTest { ConsensusParticipantConfig part0 = setting.getConsensusParticipant(0); assertEquals("jd.com", part0.getName()); assertEquals("keys/jd-com.pub", part0.getPubKeyPath()); - PubKey pubKey0 = KeyGenCommand.decodePubKey("3snPdw7i7PapsDoW185c3kfK6p8s6SwiJAdEUzgnfeuUox12nxgzXu"); + PubKey pubKey0 = KeyGenCommand.decodePubKey("3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9"); assertEquals(pubKey0, part0.getPubKey()); // assertEquals("127.0.0.1", part0.getConsensusAddress().getHost()); // assertEquals(8900, part0.getConsensusAddress().getPort()); @@ -43,7 +43,7 @@ public class LedgerInitSettingTest { ConsensusParticipantConfig part1 = setting.getConsensusParticipant(1); assertEquals(false, part1.getInitializerAddress().isSecure()); - PubKey pubKey1 = KeyGenCommand.decodePubKey("3snPdw7i7Ph1SYLQt9uqVEqiuvNXjxCdGvEdN6otJsg5rbr7Aze7kf"); + PubKey pubKey1 = KeyGenCommand.decodePubKey("3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX"); assertEquals(pubKey1, part1.getPubKey()); ConsensusParticipantConfig part2 = setting.getConsensusParticipant(2); diff --git a/source/test/test-integration/src/test/resources/ledger.init b/source/test/test-integration/src/test/resources/ledger.init index 99c3bea1..d25b002d 100644 --- a/source/test/test-integration/src/test/resources/ledger.init +++ b/source/test/test-integration/src/test/resources/ledger.init @@ -51,7 +51,7 @@ cons_parti.2.name=bt.com #第2个参与方的公钥文件路径; cons_parti.2.pubkey-path=keys/bt-com.pub #第2个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; -cons_parti.2.pubkey=3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x +cons_parti.2.pubkey= #第2个参与方的共识服务的主机地址; cons_parti.2.consensus.host=127.0.0.1 #第2个参与方的共识服务的端口; From aebfc8f3a78e3a77d7f669525a38bc466090862a Mon Sep 17 00:00:00 2001 From: shaozhuguang Date: Thu, 16 May 2019 16:53:01 +0800 Subject: [PATCH 2/2] Modify GateWay LedgerSetting Response Error Bug! --- .../gateway/web/GatewayWebServerConfigurer.java | 8 ++++++++ source/gateway/src/main/resources/gateway.conf | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/GatewayWebServerConfigurer.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/GatewayWebServerConfigurer.java index b93a8008..4481088f 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/GatewayWebServerConfigurer.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/GatewayWebServerConfigurer.java @@ -2,6 +2,13 @@ package com.jd.blockchain.gateway.web; import java.util.List; +import com.jd.blockchain.binaryproto.DataContractRegistry; +import com.jd.blockchain.consensus.ClientIdentification; +import com.jd.blockchain.consensus.ClientIdentifications; +import com.jd.blockchain.consensus.action.ActionRequest; +import com.jd.blockchain.consensus.action.ActionResponse; +import com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings; +import com.jd.blockchain.ledger.*; import com.jd.blockchain.web.serializes.ByteArrayObjectUtil; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; @@ -27,6 +34,7 @@ public class GatewayWebServerConfigurer implements WebMvcConfigurer { static { JSONSerializeUtils.disableCircularReferenceDetect(); JSONSerializeUtils.configStringSerializer(ByteArray.class); + DataContractRegistry.register(BftsmartNodeSettings.class); } diff --git a/source/gateway/src/main/resources/gateway.conf b/source/gateway/src/main/resources/gateway.conf index c8ceaf4e..c0caa7c9 100644 --- a/source/gateway/src/main/resources/gateway.conf +++ b/source/gateway/src/main/resources/gateway.conf @@ -21,10 +21,10 @@ peer.providers=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider data.retrieval.url=http://127.0.0.1:10001 #默认公钥的内容(Base58编码数据); -keys.default.pubkey=3snPdw7i7PapsDoW185c3kfK6p8s6SwiJAdEUzgnfeuUox12nxgzXu +keys.default.pubkey=3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9 #默认私钥的路径;在 pk-path 和 pk 之间必须设置其一; keys.default.privkey-path= #默认私钥的内容(加密的Base58编码数据);在 pk-path 和 pk 之间必须设置其一; -keys.default.privkey=177gjyoEUhdD1NkQSxBVvfSyovMd1ha5H46zsb9kyErLNBuQkLRAf2ea6CNjStjCFJQN8S1 +keys.default.privkey=177gjzHTznYdPgWqZrH43W3yp37onm74wYXT4v9FukpCHBrhRysBBZh7Pzdo5AMRyQGJD7x #默认私钥的解码密码; keys.default.privkey-password=DYu3G8aGTMBW1WrTw76zxQJQU4DHLw9MLyy7peG4LKkY \ No newline at end of file