diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartConsensusClientFactory.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartConsensusClientFactory.java index dc3592b6..16d8bfae 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartConsensusClientFactory.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartConsensusClientFactory.java @@ -11,7 +11,7 @@ import com.jd.blockchain.consensus.client.ClientFactory; import com.jd.blockchain.consensus.client.ClientSettings; import com.jd.blockchain.consensus.client.ConsensusClient; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.SignatureDigest; @@ -37,7 +37,7 @@ public class BftsmartConsensusClientFactory implements ClientFactory { PubKey pubKey = clientKeyPair.getPubKey(); PrivKey privKey = clientKeyPair.getPrivKey(); - SignatureFunction signatureFunction =CryptoServiceProviders.getSignatureFunction(pubKey.getAlgorithm()); + SignatureFunction signatureFunction =Crypto.getSignatureFunction(pubKey.getAlgorithm()); SignatureDigest signatureDigest = signatureFunction.sign(privKey, pubKey.toBytes()); BftsmartClientIdentification bftsmartClientIdentification = new BftsmartClientIdentification(); diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java index df2b1745..a91f3f16 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java @@ -7,7 +7,7 @@ import com.jd.blockchain.consensus.ClientIdentification; import com.jd.blockchain.consensus.ConsensusManageService; import com.jd.blockchain.consensus.bftsmart.BftsmartClientIncomingConfig; import com.jd.blockchain.consensus.bftsmart.BftsmartClientIncomingSettings; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.utils.serialize.binary.BinarySerializeUtils; @@ -54,7 +54,7 @@ public class BftsmartConsensusManageService implements ConsensusManageService { public boolean verify(ClientIdentification authId) { - SignatureFunction signatureFunction = CryptoServiceProviders + SignatureFunction signatureFunction = Crypto .getSignatureFunction(authId.getPubKey().getAlgorithm()); return signatureFunction.verify(authId.getSignature(), authId.getPubKey(), authId.getIdentityInfo()); diff --git a/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/client/MsgQueueClientFactory.java b/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/client/MsgQueueClientFactory.java index 57729f20..227a0d78 100644 --- a/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/client/MsgQueueClientFactory.java +++ b/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/client/MsgQueueClientFactory.java @@ -17,7 +17,7 @@ import com.jd.blockchain.consensus.mq.settings.MsgQueueClientIncomingSettings; import com.jd.blockchain.consensus.mq.settings.MsgQueueClientSettings; import com.jd.blockchain.consensus.mq.settings.MsgQueueConsensusSettings; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.SignatureDigest; import com.jd.blockchain.crypto.SignatureFunction; @@ -36,7 +36,7 @@ public class MsgQueueClientFactory implements ClientFactory { PubKey pubKey = clientKeyPair.getPubKey(); byte[] address = pubKey.toBytes(); // 使用公钥地址作为认证信息 - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(pubKey.getAlgorithm()); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(pubKey.getAlgorithm()); SignatureDigest signatureDigest = signatureFunction.sign(clientKeyPair.getPrivKey(), address); MsgQueueClientIdentification mqci = new MsgQueueClientIdentification() diff --git a/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/server/MsgQueueConsensusManageService.java b/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/server/MsgQueueConsensusManageService.java index 937ccfac..72368e95 100644 --- a/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/server/MsgQueueConsensusManageService.java +++ b/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/server/MsgQueueConsensusManageService.java @@ -16,7 +16,7 @@ import com.jd.blockchain.consensus.ConsensusSecurityException; import com.jd.blockchain.consensus.mq.config.MsgQueueClientIncomingConfig; import com.jd.blockchain.consensus.mq.settings.MsgQueueClientIncomingSettings; import com.jd.blockchain.consensus.mq.settings.MsgQueueConsensusSettings; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.SignatureFunction; @@ -62,7 +62,7 @@ public class MsgQueueConsensusManageService implements ConsensusManageService { byte[] identityInfo = authId.getIdentityInfo(); byte[] address = pubKey.toBytes(); // 使用公钥地址作为认证信息 if (Arrays.equals(address, identityInfo)) { - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(pubKey.getAlgorithm()); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(pubKey.getAlgorithm()); isLegal = signatureFunction.verify(authId.getSignature(), pubKey, identityInfo); } return isLegal; 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 eee908c7..dd5e9888 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 @@ -18,7 +18,7 @@ import org.junit.Test; import com.jd.blockchain.crypto.Ciphertext; import com.jd.blockchain.crypto.CryptoAlgorithm; import com.jd.blockchain.crypto.CryptoException; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.SymmetricEncryptionFunction; import com.jd.blockchain.crypto.SymmetricKey; import com.jd.blockchain.crypto.service.classic.ClassicAlgorithm; @@ -34,31 +34,31 @@ public class AESEncryptionFunctionTest { @Test public void getAlgorithmTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("aes"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); assertEquals(symmetricEncryptionFunction.getAlgorithm().name(), algorithm.name()); assertEquals(symmetricEncryptionFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("AES"); + algorithm = Crypto.getAlgorithm("AES"); assertNotNull(algorithm); assertEquals(symmetricEncryptionFunction.getAlgorithm().name(), algorithm.name()); assertEquals(symmetricEncryptionFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("aess"); + algorithm = Crypto.getAlgorithm("aess"); assertNull(algorithm); } @Test public void generateSymmetricKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("aes"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -82,10 +82,10 @@ public class AESEncryptionFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("aes"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -109,10 +109,10 @@ public class AESEncryptionFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("aes"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -154,10 +154,10 @@ public class AESEncryptionFunctionTest { @Test public void supportSymmetricKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("aes"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -165,7 +165,7 @@ public class AESEncryptionFunctionTest { assertTrue(symmetricEncryptionFunction.supportSymmetricKey(symmetricKeyBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("ripemd160"); + algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; @@ -178,10 +178,10 @@ public class AESEncryptionFunctionTest { @Test public void resolveSymmetricKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("aes"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -195,7 +195,7 @@ public class AESEncryptionFunctionTest { assertEquals((short) (ENCRYPTION_ALGORITHM | SYMMETRIC_KEY | ((byte) 26 & 0x00FF)), resolvedKey.getAlgorithm()); assertArrayEquals(symmetricKeyBytes, resolvedKey.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("ripemd160"); + algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; @@ -220,10 +220,10 @@ public class AESEncryptionFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("aes"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -233,7 +233,7 @@ public class AESEncryptionFunctionTest { byte[] ciphertextBytes = ciphertext.toBytes(); assertTrue(symmetricEncryptionFunction.supportCiphertext(ciphertextBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("ripemd160"); + algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.toBytes(); @@ -249,10 +249,10 @@ public class AESEncryptionFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("aes"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -273,7 +273,7 @@ public class AESEncryptionFunctionTest { assertArrayEquals(ciphertext.getRawCiphertext(), resolvedCiphertext.getRawCiphertext()); assertEquals(ciphertext.getAlgorithm(), resolvedCiphertext.getAlgorithm()); - algorithm = CryptoServiceProviders.getAlgorithm("ripemd160"); + algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.getRawCiphertext(); 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 ec7a1330..9b3eb88c 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 @@ -18,7 +18,7 @@ import org.junit.Test; import com.jd.blockchain.crypto.CryptoAlgorithm; import com.jd.blockchain.crypto.CryptoException; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.SignatureDigest; @@ -36,7 +36,7 @@ public class ED25519SignatureFunctionTest { public static void main(String[] args) { // Generate and output some public keys for test; - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signFunc = Crypto.getSignatureFunction("ED25519"); AsymmetricKeypair kp1 = signFunc.generateKeypair(); System.out.println("kp1.pubKey=[" + kp1.getPubKey().toBase58() + "]"); @@ -51,31 +51,31 @@ public class ED25519SignatureFunctionTest { @Test public void getAlgorithmTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("ed25519"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("ed25519"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); assertEquals(signatureFunction.getAlgorithm().name(), algorithm.name()); assertEquals(signatureFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("Ed25519"); + algorithm = Crypto.getAlgorithm("Ed25519"); assertNotNull(algorithm); assertEquals(signatureFunction.getAlgorithm().name(), algorithm.name()); assertEquals(signatureFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("eddsa"); + algorithm = Crypto.getAlgorithm("eddsa"); assertNull(algorithm); } @Test public void generateKeyPairTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("ed25519"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("ed25519"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -105,10 +105,10 @@ public class ED25519SignatureFunctionTest { @Test public void retrievePubKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("ed25519"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("ed25519"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -130,10 +130,10 @@ public class ED25519SignatureFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("ed25519"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("ed25519"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -158,10 +158,10 @@ public class ED25519SignatureFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("ed25519"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("ed25519"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -175,10 +175,10 @@ public class ED25519SignatureFunctionTest { @Test public void supportPrivKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("ed25519"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("ed25519"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -187,7 +187,7 @@ public class ED25519SignatureFunctionTest { assertTrue(signatureFunction.supportPrivKey(privKeyBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("ripemd160"); + algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; @@ -200,10 +200,10 @@ public class ED25519SignatureFunctionTest { @Test public void resolvePrivKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("ed25519"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("ed25519"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -219,7 +219,7 @@ public class ED25519SignatureFunctionTest { resolvedPrivKey.getAlgorithm()); assertArrayEquals(privKeyBytes, resolvedPrivKey.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("ripemd160"); + algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; @@ -240,10 +240,10 @@ public class ED25519SignatureFunctionTest { @Test public void supportPubKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("ed25519"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("ed25519"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -252,7 +252,7 @@ public class ED25519SignatureFunctionTest { assertTrue(signatureFunction.supportPubKey(pubKeyBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("ripemd160"); + algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; @@ -265,10 +265,10 @@ public class ED25519SignatureFunctionTest { @Test public void resolvePubKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("ed25519"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("ed25519"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -284,7 +284,7 @@ public class ED25519SignatureFunctionTest { resolvedPubKey.getAlgorithm()); assertArrayEquals(pubKeyBytes, resolvedPubKey.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("ripemd160"); + algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; @@ -309,10 +309,10 @@ public class ED25519SignatureFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("ed25519"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("ed25519"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -323,7 +323,7 @@ public class ED25519SignatureFunctionTest { byte[] signatureDigestBytes = signatureDigest.toBytes(); assertTrue(signatureFunction.supportDigest(signatureDigestBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("ripemd160"); + algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawDigestBytes = signatureDigest.toBytes(); @@ -339,10 +339,10 @@ public class ED25519SignatureFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("ed25519"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("ed25519"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -360,7 +360,7 @@ public class ED25519SignatureFunctionTest { resolvedSignatureDigest.getAlgorithm()); assertArrayEquals(signatureDigestBytes, resolvedSignatureDigest.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("ripemd160"); + algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawDigestBytes = signatureDigest.getRawDigest(); 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 325e9493..c18bc462 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 @@ -2,7 +2,7 @@ package test.com.jd.blockchain.crypto.service.classic; import com.jd.blockchain.crypto.CryptoAlgorithm; import com.jd.blockchain.crypto.CryptoException; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.crypto.service.classic.ClassicAlgorithm; @@ -25,21 +25,21 @@ public class RIPEMD160HashFunctionTest { @Test public void getAlgorithmTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("RIPEMD160"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("RIPEMD160"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); assertEquals(hashFunction.getAlgorithm().name(), algorithm.name()); assertEquals(hashFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("RIPEmd160"); + algorithm = Crypto.getAlgorithm("RIPEmd160"); assertNotNull(algorithm); assertEquals(hashFunction.getAlgorithm().name(), algorithm.name()); assertEquals(hashFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("RIPEMD-160"); + algorithm = Crypto.getAlgorithm("RIPEMD-160"); assertNull(algorithm); } @@ -50,10 +50,10 @@ public class RIPEMD160HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("RIPEMD160"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("RIPEMD160"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); byte[] rawDigestBytes = digest.getRawDigest(); @@ -83,10 +83,10 @@ public class RIPEMD160HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("RIPEMD160"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("RIPEMD160"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); @@ -99,17 +99,17 @@ public class RIPEMD160HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("RIPEMD160"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("RIPEMD160"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); byte[] digestBytes = digest.toBytes(); assertTrue(hashFunction.supportHashDigest(digestBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("aes"); + algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); System.arraycopy(algoBytes, 0, digestBytes, 0, algoBytes.length); @@ -122,10 +122,10 @@ public class RIPEMD160HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("RIPEMD160"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("RIPEMD160"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); @@ -138,7 +138,7 @@ public class RIPEMD160HashFunctionTest { assertEquals((short) (HASH_ALGORITHM | ((byte) 25 & 0x00FF)), resolvedDigest.getAlgorithm()); assertArrayEquals(digestBytes, resolvedDigest.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("aes"); + algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawDigestBytes = digest.getRawDigest(); @@ -154,7 +154,7 @@ public class RIPEMD160HashFunctionTest { assertNotNull(actualEx); assertTrue(expectedException.isAssignableFrom(actualEx.getClass())); - algorithm = CryptoServiceProviders.getAlgorithm("sha256"); + algorithm = Crypto.getAlgorithm("sha256"); assertNotNull(algorithm); algoBytes = CryptoAlgorithm.toBytes(algorithm); rawDigestBytes = digest.getRawDigest(); 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 d2ee119d..aaf34fcc 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 @@ -2,7 +2,7 @@ package test.com.jd.blockchain.crypto.service.classic; import com.jd.blockchain.crypto.CryptoAlgorithm; import com.jd.blockchain.crypto.CryptoException; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.crypto.service.classic.ClassicAlgorithm; @@ -25,21 +25,21 @@ public class SHA256HashFunctionTest { @Test public void getAlgorithmTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sha256"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sha256"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); assertEquals(hashFunction.getAlgorithm().name(), algorithm.name()); assertEquals(hashFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("SHa256"); + algorithm = Crypto.getAlgorithm("SHa256"); assertNotNull(algorithm); assertEquals(hashFunction.getAlgorithm().name(), algorithm.name()); assertEquals(hashFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("sha-256"); + algorithm = Crypto.getAlgorithm("sha-256"); assertNull(algorithm); } @@ -50,10 +50,10 @@ public class SHA256HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sha256"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sha256"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); byte[] rawDigestBytes = digest.getRawDigest(); @@ -83,10 +83,10 @@ public class SHA256HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sha256"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sha256"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); @@ -99,17 +99,17 @@ public class SHA256HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sha256"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sha256"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); byte[] digestBytes = digest.toBytes(); assertTrue(hashFunction.supportHashDigest(digestBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("aes"); + algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); System.arraycopy(algoBytes, 0, digestBytes, 0, algoBytes.length); @@ -122,10 +122,10 @@ public class SHA256HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sha256"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sha256"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); @@ -138,7 +138,7 @@ public class SHA256HashFunctionTest { assertEquals((short) (HASH_ALGORITHM | ((byte) 24 & 0x00FF)), resolvedDigest.getAlgorithm()); assertArrayEquals(digestBytes, resolvedDigest.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("aes"); + algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawDigestBytes = digest.getRawDigest(); @@ -154,7 +154,7 @@ public class SHA256HashFunctionTest { assertNotNull(actualEx); assertTrue(expectedException.isAssignableFrom(actualEx.getClass())); - algorithm = CryptoServiceProviders.getAlgorithm("ripemd160"); + algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); algoBytes = CryptoAlgorithm.toBytes(algorithm); rawDigestBytes = digest.getRawDigest(); diff --git a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoServiceProviders.java b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/Crypto.java similarity index 98% rename from source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoServiceProviders.java rename to source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/Crypto.java index d1204b58..86dbf55b 100644 --- a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoServiceProviders.java +++ b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/Crypto.java @@ -16,9 +16,9 @@ import com.jd.blockchain.provider.ProviderManager; * @author huanghaiquan * */ -public final class CryptoServiceProviders { +public final class Crypto { - private static Logger LOGGER = LoggerFactory.getLogger(CryptoServiceProviders.class); + private static Logger LOGGER = LoggerFactory.getLogger(Crypto.class); private static Map functions = new ConcurrentHashMap<>(); @@ -33,7 +33,7 @@ public final class CryptoServiceProviders { } private static void loadDefaultProviders() { - ClassLoader cl = CryptoServiceProviders.class.getClassLoader(); + ClassLoader cl = Crypto.class.getClassLoader(); pm.installAllProviders(CryptoService.class, cl); Iterable> providers = pm.getAllProviders(CryptoService.class); @@ -103,7 +103,7 @@ public final class CryptoServiceProviders { } } - private CryptoServiceProviders() { + private Crypto() { } public static Collection getAllAlgorithms() { 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 655d45f0..cb036dfb 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 @@ -23,31 +23,31 @@ public class SM2CyptoFunctionTest { @Test public void getAlgorithmTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); assertEquals(signatureFunction.getAlgorithm().name(), algorithm.name()); assertEquals(signatureFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("sM2"); + algorithm = Crypto.getAlgorithm("sM2"); assertNotNull(algorithm); assertEquals(signatureFunction.getAlgorithm().name(), algorithm.name()); assertEquals(signatureFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("sm22"); + algorithm = Crypto.getAlgorithm("sm22"); assertNull(algorithm); } @Test public void generateKeyPairTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -77,10 +77,10 @@ public class SM2CyptoFunctionTest { @Test public void retrievePubKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -102,10 +102,10 @@ public class SM2CyptoFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -132,10 +132,10 @@ public class SM2CyptoFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -153,10 +153,10 @@ public class SM2CyptoFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - AsymmetricEncryptionFunction asymmetricEncryptionFunction = CryptoServiceProviders + AsymmetricEncryptionFunction asymmetricEncryptionFunction = Crypto .getAsymmetricEncryptionFunction(algorithm); AsymmetricKeypair keyPair = asymmetricEncryptionFunction.generateKeypair(); @@ -184,10 +184,10 @@ public class SM2CyptoFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - AsymmetricEncryptionFunction asymmetricEncryptionFunction = CryptoServiceProviders + AsymmetricEncryptionFunction asymmetricEncryptionFunction = Crypto .getAsymmetricEncryptionFunction(algorithm); AsymmetricKeypair keyPair = asymmetricEncryptionFunction.generateKeypair(); @@ -205,10 +205,10 @@ public class SM2CyptoFunctionTest { @Test public void supportPrivKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -217,7 +217,7 @@ public class SM2CyptoFunctionTest { assertTrue(signatureFunction.supportPrivKey(privKeyBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; @@ -230,10 +230,10 @@ public class SM2CyptoFunctionTest { @Test public void resolvePrivKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -249,7 +249,7 @@ public class SM2CyptoFunctionTest { resolvedPrivKey.getAlgorithm()); assertArrayEquals(privKeyBytes, resolvedPrivKey.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; @@ -270,10 +270,10 @@ public class SM2CyptoFunctionTest { @Test public void supportPubKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -282,7 +282,7 @@ public class SM2CyptoFunctionTest { assertTrue(signatureFunction.supportPubKey(pubKeyBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; @@ -295,10 +295,10 @@ public class SM2CyptoFunctionTest { @Test public void resolvePubKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -314,7 +314,7 @@ public class SM2CyptoFunctionTest { resolvedPubKey.getAlgorithm()); assertArrayEquals(pubKeyBytes, resolvedPubKey.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; @@ -339,10 +339,10 @@ public class SM2CyptoFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -353,7 +353,7 @@ public class SM2CyptoFunctionTest { byte[] signatureDigestBytes = signatureDigest.toBytes(); assertTrue(signatureFunction.supportDigest(signatureDigestBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawDigestBytes = signatureDigest.toBytes(); @@ -369,10 +369,10 @@ public class SM2CyptoFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(algorithm); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(algorithm); AsymmetricKeypair keyPair = signatureFunction.generateKeypair(); @@ -390,7 +390,7 @@ public class SM2CyptoFunctionTest { resolvedSignatureDigest.getAlgorithm()); assertArrayEquals(signatureDigestBytes, resolvedSignatureDigest.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawDigestBytes = signatureDigest.getRawDigest(); @@ -414,10 +414,10 @@ public class SM2CyptoFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - AsymmetricEncryptionFunction asymmetricEncryptionFunction = CryptoServiceProviders + AsymmetricEncryptionFunction asymmetricEncryptionFunction = Crypto .getAsymmetricEncryptionFunction(algorithm); AsymmetricKeypair keyPair = asymmetricEncryptionFunction.generateKeypair(); @@ -430,7 +430,7 @@ public class SM2CyptoFunctionTest { assertTrue(asymmetricEncryptionFunction.supportCiphertext(ciphertextBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.toBytes(); @@ -446,10 +446,10 @@ public class SM2CyptoFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm2"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm2"); assertNotNull(algorithm); - AsymmetricEncryptionFunction asymmetricEncryptionFunction = CryptoServiceProviders + AsymmetricEncryptionFunction asymmetricEncryptionFunction = Crypto .getAsymmetricEncryptionFunction(algorithm); AsymmetricKeypair keyPair = asymmetricEncryptionFunction.generateKeypair(); @@ -468,7 +468,7 @@ public class SM2CyptoFunctionTest { resolvedCiphertext.getAlgorithm()); assertArrayEquals(ciphertextBytes, resolvedCiphertext.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.getRawCiphertext(); 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 801f0b38..5383bfce 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 @@ -2,7 +2,7 @@ package test.com.jd.blockchain.crypto.service.sm; import com.jd.blockchain.crypto.CryptoAlgorithm; import com.jd.blockchain.crypto.CryptoException; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.crypto.service.sm.SMAlgorithm; @@ -23,21 +23,21 @@ import static org.junit.Assert.*; public class SM3HashFunctionTest { @Test public void getAlgorithmTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); assertEquals(hashFunction.getAlgorithm().name(), algorithm.name()); assertEquals(hashFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("Sm3"); + algorithm = Crypto.getAlgorithm("Sm3"); assertNotNull(algorithm); assertEquals(hashFunction.getAlgorithm().name(), algorithm.name()); assertEquals(hashFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("sm3333"); + algorithm = Crypto.getAlgorithm("sm3333"); assertNull(algorithm); } @@ -48,10 +48,10 @@ public class SM3HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); byte[] rawDigestBytes = digest.getRawDigest(); @@ -81,10 +81,10 @@ public class SM3HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); @@ -97,17 +97,17 @@ public class SM3HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); byte[] digestBytes = digest.toBytes(); assertTrue(hashFunction.supportHashDigest(digestBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("sm4"); + algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); System.arraycopy(algoBytes, 0, digestBytes, 0, algoBytes.length); @@ -120,10 +120,10 @@ public class SM3HashFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - HashFunction hashFunction = CryptoServiceProviders.getHashFunction(algorithm); + HashFunction hashFunction = Crypto.getHashFunction(algorithm); HashDigest digest = hashFunction.hash(data); @@ -136,7 +136,7 @@ public class SM3HashFunctionTest { assertEquals((short) (HASH_ALGORITHM | ((byte) 3 & 0x00FF)), resolvedDigest.getAlgorithm()); assertArrayEquals(digestBytes, resolvedDigest.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("sm4"); + algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawDigestBytes = digest.getRawDigest(); 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 ead9d676..d8c4e86d 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 @@ -18,7 +18,7 @@ import org.junit.Test; import com.jd.blockchain.crypto.Ciphertext; import com.jd.blockchain.crypto.CryptoAlgorithm; import com.jd.blockchain.crypto.CryptoException; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.SymmetricEncryptionFunction; import com.jd.blockchain.crypto.SymmetricKey; import com.jd.blockchain.crypto.service.sm.SMAlgorithm; @@ -33,31 +33,31 @@ import com.jd.blockchain.utils.io.BytesUtils; public class SM4EncryptionFunctionTest { @Test public void getAlgorithmTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm4"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); assertEquals(symmetricEncryptionFunction.getAlgorithm().name(), algorithm.name()); assertEquals(symmetricEncryptionFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("sM4"); + algorithm = Crypto.getAlgorithm("sM4"); assertNotNull(algorithm); assertEquals(symmetricEncryptionFunction.getAlgorithm().name(), algorithm.name()); assertEquals(symmetricEncryptionFunction.getAlgorithm().code(), algorithm.code()); - algorithm = CryptoServiceProviders.getAlgorithm("smm4"); + algorithm = Crypto.getAlgorithm("smm4"); assertNull(algorithm); } @Test public void generateSymmetricKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm4"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -81,10 +81,10 @@ public class SM4EncryptionFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm4"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -108,10 +108,10 @@ public class SM4EncryptionFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm4"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -152,10 +152,10 @@ public class SM4EncryptionFunctionTest { @Test public void supportSymmetricKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm4"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -163,7 +163,7 @@ public class SM4EncryptionFunctionTest { assertTrue(symmetricEncryptionFunction.supportSymmetricKey(symmetricKeyBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; @@ -175,10 +175,10 @@ public class SM4EncryptionFunctionTest { @Test public void resolveSymmetricKeyTest() { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm4"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -192,7 +192,7 @@ public class SM4EncryptionFunctionTest { assertEquals((short) (ENCRYPTION_ALGORITHM | SYMMETRIC_KEY | ((byte) 4 & 0x00FF)), resolvedKey.getAlgorithm()); assertArrayEquals(symmetricKeyBytes, resolvedKey.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; @@ -217,10 +217,10 @@ public class SM4EncryptionFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm4"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -230,7 +230,7 @@ public class SM4EncryptionFunctionTest { byte[] ciphertextBytes = ciphertext.toBytes(); assertTrue(symmetricEncryptionFunction.supportCiphertext(ciphertextBytes)); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.toBytes(); @@ -246,10 +246,10 @@ public class SM4EncryptionFunctionTest { Random random = new Random(); random.nextBytes(data); - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("sm4"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - SymmetricEncryptionFunction symmetricEncryptionFunction = CryptoServiceProviders + SymmetricEncryptionFunction symmetricEncryptionFunction = Crypto .getSymmetricEncryptionFunction(algorithm); SymmetricKey symmetricKey = (SymmetricKey) symmetricEncryptionFunction.generateSymmetricKey(); @@ -266,7 +266,7 @@ public class SM4EncryptionFunctionTest { resolvedCiphertext.getAlgorithm()); assertArrayEquals(ciphertextBytes, resolvedCiphertext.toBytes()); - algorithm = CryptoServiceProviders.getAlgorithm("sm3"); + algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.getRawCiphertext(); diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/TxProcessingController.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/TxProcessingController.java index 54e97c57..02ac7fc6 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/TxProcessingController.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/TxProcessingController.java @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.gateway.PeerService; @@ -55,7 +55,7 @@ public class TxProcessingController implements TransactionService { // 验证签名; byte[] content = BinaryEncodingUtils.encode(txRequest.getTransactionContent(), TransactionContent.class); for (DigitalSignature sign : partiSigns) { - SignatureFunction signFunc = CryptoServiceProviders + SignatureFunction signFunc = Crypto .getSignatureFunction(sign.getPubKey().getAlgorithm()); if (!signFunc.verify(sign.getDigest(), sign.getPubKey(), content)) { throw new BusinessException("The validation of participant signatures fail!"); diff --git a/source/gateway/src/test/java/test/com/jd/blockchain/gateway/data/HashDigestJSONSerializeTest.java b/source/gateway/src/test/java/test/com/jd/blockchain/gateway/data/HashDigestJSONSerializeTest.java index badb1f73..61bbcfc9 100644 --- a/source/gateway/src/test/java/test/com/jd/blockchain/gateway/data/HashDigestJSONSerializeTest.java +++ b/source/gateway/src/test/java/test/com/jd/blockchain/gateway/data/HashDigestJSONSerializeTest.java @@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.utils.serialize.json.JSONSerializeUtils; @@ -41,7 +41,7 @@ public class HashDigestJSONSerializeTest { JSONSerializeUtils.configSerialization(HashDigest.class, HashDigestSerializer.INSTANCE, HashDigestDeserializer.INSTANCE); - HashFunction hashFunc = CryptoServiceProviders.getHashFunction("SHA256"); + HashFunction hashFunc = Crypto.getHashFunction("SHA256"); HashDigest hash = hashFunc.hash("jd-test".getBytes()); String hashJson = JSONSerializeUtils.serializeToJSON(hash, true); diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminAccount.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminAccount.java index a12536c7..32ba3090 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminAccount.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminAccount.java @@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.binaryproto.DataContractRegistry; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.ledger.LedgerInitSetting; @@ -157,7 +157,7 @@ public class LedgerAdminAccount implements Transactional, LedgerAdministration { // String key = encodeMetadataKey(base58Hash); Bytes key = encodeMetadataKey(adminAccountHash); byte[] bytes = settingsStorage.get(key); - HashFunction hashFunc = CryptoServiceProviders.getHashFunction(adminAccountHash.getAlgorithm()); + HashFunction hashFunc = Crypto.getHashFunction(adminAccountHash.getAlgorithm()); if (!hashFunc.verify(adminAccountHash, bytes)) { LOGGER.error("The hash verification of ledger settings fail! --[HASH=" + key + "]"); throw new LedgerException("The hash verification of ledger settings fail!"); @@ -262,7 +262,7 @@ public class LedgerAdminAccount implements Transactional, LedgerAdministration { // 基于之前的密码配置来计算元数据的哈希; byte[] metadataBytes = serializeMetadata(metadata); - HashFunction hashFunc = CryptoServiceProviders + HashFunction hashFunc = Crypto .getHashFunction(previousSetting.getCryptoSetting().getHashAlgorithm()); HashDigest metadataHash = hashFunc.hash(metadataBytes); if (adminAccountHash == null || !adminAccountHash.equals(metadataHash)) { diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleTree.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleTree.java index bbeeba8d..f124c82d 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleTree.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleTree.java @@ -15,7 +15,7 @@ import java.util.concurrent.RecursiveTask; import java.util.concurrent.atomic.AtomicLong; import com.jd.blockchain.crypto.CryptoAlgorithm; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.ledger.CryptoSetting; @@ -1413,7 +1413,7 @@ public class MerkleTree implements Transactional { int totalSize = getBodySize(); byte[] bodyBytes = new byte[totalSize]; generateBodyBytes(bodyBytes); - HashFunction hashFunc = CryptoServiceProviders.getHashFunction(hashAlgorithm); + HashFunction hashFunc = Crypto.getHashFunction(hashAlgorithm); return hashFunc.hash(bodyBytes); } @@ -1476,7 +1476,7 @@ public class MerkleTree implements Transactional { byte[] dataBytes = BytesUtils.concat(bodyBytes, hashedData); - HashFunction hashFunc = CryptoServiceProviders.getHashFunction(hashAlgorithm); + HashFunction hashFunc = Crypto.getHashFunction(hashAlgorithm); HashDigest dataHash = hashFunc.hash(dataBytes); int hashMaskSize = NumberMask.TINY.getMaskLength(dataHash.size()); diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java index 52a05d87..4f6fe856 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java @@ -1,7 +1,7 @@ package com.jd.blockchain.ledger.core.impl; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.ledger.BlockBody; @@ -231,7 +231,7 @@ public class LedgerRepositoryImpl implements LedgerRepository { } else { blockBodyBytes = BinaryEncodingUtils.encode(block, BlockBody.class); } - HashFunction hashFunc = CryptoServiceProviders.getHashFunction(blockHash.getAlgorithm()); + HashFunction hashFunc = Crypto.getHashFunction(blockHash.getAlgorithm()); boolean pass = hashFunc.verify(blockHash, blockBodyBytes); if (!pass) { throw new LedgerException("Block hash verification fail!"); diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerTransactionalEditor.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerTransactionalEditor.java index b207d5b6..7fe5dd51 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerTransactionalEditor.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerTransactionalEditor.java @@ -3,7 +3,7 @@ package com.jd.blockchain.ledger.core.impl; import java.util.Stack; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.ledger.BlockBody; import com.jd.blockchain.ledger.CryptoSetting; @@ -189,7 +189,7 @@ public class LedgerTransactionalEditor implements LedgerEditor { // compute block hash; byte[] blockBodyBytes = BinaryEncodingUtils.encode(newlyBlock, BlockBody.class); - HashDigest blockHash = CryptoServiceProviders.getHashFunction(cryptoSetting.getHashAlgorithm()) + HashDigest blockHash = Crypto.getHashFunction(cryptoSetting.getHashAlgorithm()) .hash(blockBodyBytes); newlyBlock.setHash(blockHash); if (newlyBlock.getLedgerHash() == null) { diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerEditerTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerEditerTest.java index d9fe9fb5..047e4066 100644 --- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerEditerTest.java +++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerEditerTest.java @@ -10,7 +10,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.crypto.AddressEncoding; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.crypto.service.classic.ClassicAlgorithm; import com.jd.blockchain.ledger.BlockchainKeypair; @@ -42,7 +42,7 @@ public class LedgerEditerTest { } String ledgerKeyPrefix = "LDG://"; - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519"); // 存储; MemoryKVStorage storage = new MemoryKVStorage(); @@ -108,7 +108,7 @@ public class LedgerEditerTest { } private LedgerInitSetting createLedgerInitSetting() { - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signFunc = Crypto.getSignatureFunction("ED25519"); CryptoConfig defCryptoSetting = new CryptoConfig(); defCryptoSetting.setAutoVerifyHash(true); diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerManagerTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerManagerTest.java index d25f0f0e..637828f8 100644 --- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerManagerTest.java +++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerManagerTest.java @@ -12,7 +12,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.crypto.AddressEncoding; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.crypto.service.classic.ClassicAlgorithm; @@ -60,7 +60,7 @@ public class LedgerManagerTest { @Before public void intialize() { - signatureFunction = CryptoServiceProviders.getSignatureFunction("ED25519"); + signatureFunction = Crypto.getSignatureFunction("ED25519"); } @Test diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTestUtils.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTestUtils.java index edf0a0cb..28a01823 100644 --- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTestUtils.java +++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTestUtils.java @@ -3,7 +3,7 @@ package test.com.jd.blockchain.ledger; import java.util.Random; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.SignatureFunction; @@ -25,7 +25,7 @@ public class LedgerTestUtils { private static Random rand = new Random(); public static TransactionRequest createTxRequest(HashDigest ledgerHash) { - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signFunc = Crypto.getSignatureFunction("ED25519"); return createTxRequest(ledgerHash, signFunc); } @@ -72,7 +72,7 @@ public class LedgerTestUtils { public static HashDigest generateRandomHash() { byte[] data = new byte[64]; rand.nextBytes(data); - return CryptoServiceProviders.getHashFunction("SHA256").hash(data); + return Crypto.getHashFunction("SHA256").hash(data); } public static CryptoSetting createDefaultCryptoSetting() { diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTransactionDataTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTransactionDataTest.java index 52adeebb..bfff2a7c 100644 --- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTransactionDataTest.java +++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTransactionDataTest.java @@ -17,7 +17,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.binaryproto.DataContractRegistry; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.SignatureDigest; @@ -249,7 +249,7 @@ public class LedgerTransactionDataTest { private TransactionContent initTransactionContent() throws Exception { TxContentBlob contentBlob = null; BlockchainKeypair id = BlockchainKeyGenerator.getInstance().generate(ClassicAlgorithm.ED25519); - HashDigest ledgerHash = CryptoServiceProviders.getHashFunction("SHA256") + HashDigest ledgerHash = Crypto.getHashFunction("SHA256") .hash(UUID.randomUUID().toString().getBytes("UTF-8")); BlockchainOperationFactory opFactory = new BlockchainOperationFactory(); contentBlob = new TxContentBlob(ledgerHash); diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BlockchainKeyGenerator.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BlockchainKeyGenerator.java index 4e4d6fe5..6d751f87 100644 --- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BlockchainKeyGenerator.java +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BlockchainKeyGenerator.java @@ -2,7 +2,7 @@ package com.jd.blockchain.ledger; import com.jd.blockchain.crypto.CryptoAlgorithm; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.SignatureFunction; /** @@ -27,12 +27,12 @@ public class BlockchainKeyGenerator { } public BlockchainKeypair generate(String algorithmName) { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm(algorithmName); + CryptoAlgorithm algorithm = Crypto.getAlgorithm(algorithmName); return generate(algorithm); } public BlockchainKeypair generate(CryptoAlgorithm signatureAlgorithm) { - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction(signatureAlgorithm); + SignatureFunction signFunc = Crypto.getSignatureFunction(signatureAlgorithm); AsymmetricKeypair cryptoKeyPair = signFunc.generateKeypair(); return new BlockchainKeypair(cryptoKeyPair.getPubKey(), cryptoKeyPair.getPrivKey()); } diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/PreparedTx.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/PreparedTx.java index 9068405c..02c74a84 100644 --- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/PreparedTx.java +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/PreparedTx.java @@ -2,7 +2,7 @@ package com.jd.blockchain.ledger.data; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.SignatureDigest; @@ -37,7 +37,7 @@ public class PreparedTx implements PreparedTransaction { @Override public DigitalSignature sign(AsymmetricKeypair keyPair) { - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(keyPair.getAlgorithm()); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(keyPair.getAlgorithm()); PrivKey privKey = keyPair.getPrivKey(); byte[] content = BinaryEncodingUtils.encode(getTransactionContent(), TransactionContent.class); SignatureDigest signatureDigest = signatureFunction.sign(privKey, content); diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/TxBuilder.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/TxBuilder.java index cd0aca41..0b6bfa48 100644 --- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/TxBuilder.java +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/TxBuilder.java @@ -2,7 +2,7 @@ package com.jd.blockchain.ledger.data; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.binaryproto.DataContractRegistry; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.ledger.TransactionBuilder; import com.jd.blockchain.ledger.TransactionContent; @@ -43,7 +43,7 @@ public class TxBuilder implements TransactionBuilder { txContent.addOperations(opFactory.getOperations()); byte[] contentBodyBytes = BinaryEncodingUtils.encode(txContent, TransactionContentBody.class); - HashDigest contentHash = CryptoServiceProviders.getHashFunction(DEFAULT_HASH_ALGORITHM).hash(contentBodyBytes); + HashDigest contentHash = Crypto.getHashFunction(DEFAULT_HASH_ALGORITHM).hash(contentBodyBytes); txContent.setHash(contentHash); return txContent; diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/TxRequestBuilder.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/TxRequestBuilder.java index 0c639b4d..848f1e3d 100644 --- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/TxRequestBuilder.java +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/data/TxRequestBuilder.java @@ -5,7 +5,7 @@ import java.util.List; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.PubKey; @@ -71,12 +71,12 @@ public class TxRequestBuilder implements TransactionRequestBuilder { } public static SignatureDigest sign(TransactionContent txContent, PrivKey privKey) { - return CryptoServiceProviders.getSignatureFunction(privKey.getAlgorithm()).sign(privKey, + return Crypto.getSignatureFunction(privKey.getAlgorithm()).sign(privKey, txContent.getHash().toBytes()); } public static boolean verifySignature(TransactionContent txContent, SignatureDigest signDigest, PubKey pubKey) { - return CryptoServiceProviders.getSignatureFunction(pubKey.getAlgorithm()).verify(signDigest, pubKey, + return Crypto.getSignatureFunction(pubKey.getAlgorithm()).verify(signDigest, pubKey, txContent.getHash().toBytes()); } @@ -87,7 +87,7 @@ public class TxRequestBuilder implements TransactionRequestBuilder { txMessage.addNodeSignatures(nodeSignatures); byte[] reqBytes = BinaryEncodingUtils.encode(txMessage, NodeRequest.class); - HashDigest reqHash = CryptoServiceProviders.getHashFunction(DEFAULT_HASH_ALGORITHM).hash(reqBytes); + HashDigest reqHash = Crypto.getHashFunction(DEFAULT_HASH_ALGORITHM).hash(reqBytes); txMessage.setHash(reqHash); return txMessage; diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ContractCodeDeployOpTemplateTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ContractCodeDeployOpTemplateTest.java index 97f59d9e..cbdbe67f 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ContractCodeDeployOpTemplateTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ContractCodeDeployOpTemplateTest.java @@ -17,7 +17,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.binaryproto.DataContractRegistry; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.ledger.BlockchainIdentity; @@ -42,7 +42,7 @@ public class ContractCodeDeployOpTemplateTest { public void initContractCodeDeployOpTemplate() { DataContractRegistry.register(ContractCodeDeployOperation.class); DataContractRegistry.register(Operation.class); - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signFunc = Crypto.getSignatureFunction("ED25519"); PubKey pubKey = signFunc.generateKeypair().getPubKey(); BlockchainIdentity contractID = new BlockchainIdentityData(pubKey); byte[] chainCode = "jd-test".getBytes(); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DataAccountRegisterOpTemplateTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DataAccountRegisterOpTemplateTest.java index d8fd0695..207f5e42 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DataAccountRegisterOpTemplateTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DataAccountRegisterOpTemplateTest.java @@ -15,7 +15,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.binaryproto.DataContractRegistry; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.ledger.BlockchainIdentity; @@ -39,7 +39,7 @@ public class DataAccountRegisterOpTemplateTest { public void initDataAccountRegisterOpTemplate() { DataContractRegistry.register(DataAccountRegisterOperation.class); DataContractRegistry.register(Operation.class); - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signFunc = Crypto.getSignatureFunction("ED25519"); PubKey pubKey = signFunc.generateKeypair().getPubKey(); BlockchainIdentity contractID = new BlockchainIdentityData(pubKey); data = new DataAccountRegisterOpTemplate(contractID); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DigitalSignatureBlobTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DigitalSignatureBlobTest.java index 52629988..ac0bc568 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DigitalSignatureBlobTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DigitalSignatureBlobTest.java @@ -17,7 +17,7 @@ import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.crypto.CryptoAlgorithm; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.SignatureDigest; import com.jd.blockchain.crypto.SignatureFunction; @@ -40,7 +40,7 @@ public class DigitalSignatureBlobTest { public void initDigitalSignatureBlob() throws Exception { DataContractRegistry.register(DigitalSignature.class); DataContractRegistry.register(DigitalSignatureBody.class); - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signFunc = Crypto.getSignatureFunction("ED25519"); AsymmetricKeypair kp = signFunc.generateKeypair(); PubKey pubKey = kp.getPubKey(); 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 ff6d42f1..6d6113c6 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 @@ -5,7 +5,7 @@ import java.util.Random; import org.junit.Test; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.utils.security.Ed25519Utils; @@ -17,7 +17,7 @@ public class ED25519SignatureTest { byte[] data = new byte[64]; rand.nextBytes(data); - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signFunc = Crypto.getSignatureFunction("ED25519"); AsymmetricKeypair key = signFunc.generateKeypair(); byte[] pubKey = key.getPubKey().getRawKeyBytes(); byte[] privKey = key.getPrivKey().getRawKeyBytes(); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxContentBlobTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxContentBlobTest.java index c01e3f53..20f0e8d0 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxContentBlobTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxContentBlobTest.java @@ -11,7 +11,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.binaryproto.DataContractRegistry; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.ledger.BlockchainKeyGenerator; import com.jd.blockchain.ledger.BlockchainKeypair; @@ -36,14 +36,14 @@ public class TxContentBlobTest { BlockchainKeypair id = BlockchainKeyGenerator.getInstance().generate("ED25519"); - HashDigest ledgerHash = CryptoServiceProviders.getHashFunction("SHA256") + HashDigest ledgerHash = Crypto.getHashFunction("SHA256") .hash(UUID.randomUUID().toString().getBytes("UTF-8")); BlockchainOperationFactory opFactory = new BlockchainOperationFactory(); contentBlob = new TxContentBlob(ledgerHash); - HashDigest contentHash = CryptoServiceProviders.getHashFunction("SHA256") + HashDigest contentHash = Crypto.getHashFunction("SHA256") .hash("jd.com".getBytes()); contentBlob.setHash(contentHash); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxRequestMessageTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxRequestMessageTest.java index 72282f9f..7434ec66 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxRequestMessageTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxRequestMessageTest.java @@ -18,7 +18,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.crypto.SignatureDigest; @@ -59,7 +59,7 @@ public class TxRequestMessageTest { data = new TxRequestMessage(initTransactionContent()); - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signFunc = Crypto.getSignatureFunction("ED25519"); AsymmetricKeypair key1 = signFunc.generateKeypair(); AsymmetricKeypair key2 = signFunc.generateKeypair(); AsymmetricKeypair key3 = signFunc.generateKeypair(); @@ -79,7 +79,7 @@ public class TxRequestMessageTest { data.addNodeSignatures(node1); data.addNodeSignatures(node2); - HashDigest hash = CryptoServiceProviders.getHashFunction("SHA256").hash("DATA".getBytes()); + HashDigest hash = Crypto.getHashFunction("SHA256").hash("DATA".getBytes()); data.setHash(hash); } @@ -196,7 +196,7 @@ public class TxRequestMessageTest { private TransactionContent initTransactionContent() throws Exception { TxContentBlob contentBlob = null; BlockchainKeypair id = BlockchainKeyGenerator.getInstance().generate("ED25519"); - HashFunction hashFunc = CryptoServiceProviders.getHashFunction("SHA256"); + HashFunction hashFunc = Crypto.getHashFunction("SHA256"); HashDigest ledgerHash = hashFunc.hash(UUID.randomUUID().toString().getBytes("UTF-8")); BlockchainOperationFactory opFactory = new BlockchainOperationFactory(); contentBlob = new TxContentBlob(ledgerHash); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxResponseMessageTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxResponseMessageTest.java index ac73a189..69f0dea0 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxResponseMessageTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxResponseMessageTest.java @@ -15,7 +15,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.binaryproto.DataContractRegistry; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.ledger.TransactionResponse; @@ -36,7 +36,7 @@ public class TxResponseMessageTest { @Before public void initTxRequestMessage() throws Exception { DataContractRegistry.register(TransactionResponse.class); - HashFunction hashFunc = CryptoServiceProviders.getHashFunction("SHA256"); + HashFunction hashFunc = Crypto.getHashFunction("SHA256"); HashDigest contentHash = hashFunc.hash("jd-content".getBytes()); HashDigest blockHash = hashFunc.hash("jd-block".getBytes()); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/UserRegisterOpTemplateTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/UserRegisterOpTemplateTest.java index b231842e..2d79c03d 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/UserRegisterOpTemplateTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/UserRegisterOpTemplateTest.java @@ -16,7 +16,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.ledger.BlockchainIdentity; import com.jd.blockchain.ledger.BlockchainIdentityData; @@ -39,7 +39,7 @@ public class UserRegisterOpTemplateTest { public void initUserRegisterOpTemplate() { DataContractRegistry.register(UserRegisterOperation.class); DataContractRegistry.register(Operation.class); - AsymmetricKeypair key = CryptoServiceProviders.getSignatureFunction("ED25519").generateKeypair(); + AsymmetricKeypair key = Crypto.getSignatureFunction("ED25519").generateKeypair(); PubKey pubKey = key.getPubKey(); BlockchainIdentity contractID = new BlockchainIdentityData(pubKey); data = new UserRegisterOpTemplate(contractID); diff --git a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/NodeSigningAppender.java b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/NodeSigningAppender.java index 78e6b435..8b4c3aad 100644 --- a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/NodeSigningAppender.java +++ b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/NodeSigningAppender.java @@ -5,7 +5,7 @@ import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.consensus.MessageService; import com.jd.blockchain.consensus.client.ConsensusClient; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.crypto.SignatureDigest; @@ -66,13 +66,13 @@ public class NodeSigningAppender implements TransactionService { byte[] endpointRequestBytes = BinaryEncodingUtils.encode(txMessage, TransactionRequest.class); short signAlgorithm = nodeKeyPair.getAlgorithm(); - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction(signAlgorithm); + SignatureFunction signFunc = Crypto.getSignatureFunction(signAlgorithm); SignatureDigest signDigest = signFunc.sign(nodeKeyPair.getPrivKey(), endpointRequestBytes); txMessage.addNodeSignatures(new DigitalSignatureBlob(nodeKeyPair.getPubKey(), signDigest)); // 计算交易哈希; byte[] nodeRequestBytes = BinaryEncodingUtils.encode(txMessage, TransactionRequest.class); - HashFunction hashFunc = CryptoServiceProviders.getHashFunction(signAlgorithm); + HashFunction hashFunc = Crypto.getHashFunction(signAlgorithm); HashDigest txHash = hashFunc.hash(nodeRequestBytes); txMessage.setHash(txHash); diff --git a/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/GatewayServiceFactory.java b/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/GatewayServiceFactory.java index 2f1b688c..ba0d9eaa 100644 --- a/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/GatewayServiceFactory.java +++ b/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/GatewayServiceFactory.java @@ -3,7 +3,7 @@ package com.jd.blockchain.sdk.client; import java.io.Closeable; import com.jd.blockchain.binaryproto.BinaryEncodingUtils; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.SignatureDigest; import com.jd.blockchain.crypto.SignatureFunction; @@ -138,7 +138,7 @@ public class GatewayServiceFactory implements BlockchainServiceFactory, Closeabl byte[] txContentBytes = BinaryEncodingUtils.encode(txRequest.getTransactionContent(), TransactionContent.class); PrivKey userPrivKey = userKey.getPrivKey(); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction(userKey.getAlgorithm()); + SignatureFunction signatureFunction = Crypto.getSignatureFunction(userKey.getAlgorithm()); if (signatureFunction != null) { SignatureDigest signatureDigest = signatureFunction.sign(userPrivKey, txContentBytes); DigitalSignature signature = new DigitalSignatureBlob(userKey.getPubKey(), signatureDigest); diff --git a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Contract.java b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Contract.java index b09abc7a..ef0753bd 100644 --- a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Contract.java +++ b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Contract.java @@ -1,7 +1,7 @@ package com.jd.blockchain.sdk.samples; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.ledger.BlockchainKeyGenerator; @@ -108,7 +108,7 @@ public class SDKDemo_Contract { * @return */ private static AsymmetricKeypair getSponsorKey() { - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519"); return signatureFunction.generateKeypair(); } diff --git a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_DataAccount.java b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_DataAccount.java index 750c94aa..4e873605 100644 --- a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_DataAccount.java +++ b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_DataAccount.java @@ -1,7 +1,7 @@ package com.jd.blockchain.sdk.samples; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.ledger.BlockchainKeyGenerator; @@ -74,7 +74,7 @@ public class SDKDemo_DataAccount { } private static AsymmetricKeypair getSponsorKey() { - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519"); return signatureFunction.generateKeypair(); } diff --git a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_InsertData.java b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_InsertData.java index 68a67359..abe4bc2a 100644 --- a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_InsertData.java +++ b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_InsertData.java @@ -1,7 +1,7 @@ package com.jd.blockchain.sdk.samples; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.ledger.BlockchainKeyGenerator; @@ -80,7 +80,7 @@ public class SDKDemo_InsertData { } private static AsymmetricKeypair getSponsorKey() { - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519"); return signatureFunction.generateKeypair(); } diff --git a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Query.java b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Query.java index 7d575107..3205fd73 100644 --- a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Query.java +++ b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Query.java @@ -1,6 +1,6 @@ package com.jd.blockchain.sdk.samples; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.ledger.BlockchainKeyGenerator; import com.jd.blockchain.ledger.BlockchainKeypair; @@ -22,7 +22,7 @@ public class SDKDemo_Query { public static BlockchainKeypair CLIENT_CERT = BlockchainKeyGenerator.getInstance().generate("ED25519"); - public static final HashDigest LEDGER_HASH = CryptoServiceProviders.getHashFunction("SHA256") + public static final HashDigest LEDGER_HASH = Crypto.getHashFunction("SHA256") .hash("xkxjcioewfqwe".getBytes()); /** diff --git a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_User.java b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_User.java index 17f78c8d..5fc67f3c 100644 --- a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_User.java +++ b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_User.java @@ -1,7 +1,7 @@ package com.jd.blockchain.sdk.samples; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.ledger.BlockchainKeyGenerator; @@ -63,7 +63,7 @@ public class SDKDemo_User { //BlockchainKeyGenerator generator = BlockchainKeyGenerator.getInstance(); //BlockchainKeyPair user = generator.generate(CryptoKeyType.PUBLIC); - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519"); AsymmetricKeypair cryptoKeyPair = signatureFunction.generateKeypair(); BlockchainKeypair user = new BlockchainKeypair(cryptoKeyPair.getPubKey(), cryptoKeyPair.getPrivKey()); @@ -88,7 +88,7 @@ public class SDKDemo_User { } private static AsymmetricKeypair getSponsorKey() { - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519"); return signatureFunction.generateKeypair(); } diff --git a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_BatchInsertData_Test_.java b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_BatchInsertData_Test_.java index 59be42e6..c7dae27f 100644 --- a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_BatchInsertData_Test_.java +++ b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_BatchInsertData_Test_.java @@ -15,7 +15,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.crypto.SignatureFunction; @@ -124,12 +124,12 @@ public class SDK_GateWay_BatchInsertData_Test_ { private AsymmetricKeypair getSponsorKey() { - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519"); return signatureFunction.generateKeypair(); } private TransactionResponse initResponse() { - HashFunction hashFunc = CryptoServiceProviders.getHashFunction("SHA256");; + HashFunction hashFunc = Crypto.getHashFunction("SHA256");; HashDigest contentHash = hashFunc.hash("contentHash".getBytes()); HashDigest blockHash = hashFunc.hash("blockHash".getBytes()); long blockHeight = 9998L; diff --git a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_DataAccount_Test_.java b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_DataAccount_Test_.java index 014ed044..4976b92b 100644 --- a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_DataAccount_Test_.java +++ b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_DataAccount_Test_.java @@ -13,7 +13,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.crypto.SignatureFunction; @@ -109,13 +109,13 @@ public class SDK_GateWay_DataAccount_Test_ { } private HashDigest getLedgerHash() { - HashFunction hashFunc = CryptoServiceProviders.getHashFunction("SHA256");; + HashFunction hashFunc = Crypto.getHashFunction("SHA256");; HashDigest ledgerHash =hashFunc.hash("jd-gateway".getBytes()); return ledgerHash; } private SignatureFunction getSignatureFunction() { - return CryptoServiceProviders.getSignatureFunction("ED25519"); + return Crypto.getSignatureFunction("ED25519"); } private AsymmetricKeypair getSponsorKey() { @@ -123,7 +123,7 @@ public class SDK_GateWay_DataAccount_Test_ { } private TransactionResponse initResponse() { - HashFunction hashFunc = CryptoServiceProviders.getHashFunction("SHA256");; + HashFunction hashFunc = Crypto.getHashFunction("SHA256");; HashDigest contentHash = hashFunc.hash("contentHash".getBytes()); HashDigest blockHash = hashFunc.hash("blockHash".getBytes()); long blockHeight = 9998L; diff --git a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_InsertData_Test_.java b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_InsertData_Test_.java index 8653a00b..ccf6f333 100644 --- a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_InsertData_Test_.java +++ b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_InsertData_Test_.java @@ -15,7 +15,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.crypto.SignatureFunction; @@ -111,19 +111,19 @@ public class SDK_GateWay_InsertData_Test_ { } private HashDigest getLedgerHash() { - HashFunction hashFunc = CryptoServiceProviders.getHashFunction("SHA256"); + HashFunction hashFunc = Crypto.getHashFunction("SHA256"); HashDigest ledgerHash = hashFunc.hash("jd-gateway".getBytes()); return ledgerHash; } private AsymmetricKeypair getSponsorKey() { - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519"); return signatureFunction.generateKeypair(); } private TransactionResponse initResponse() { - HashFunction hashFunc = CryptoServiceProviders.getHashFunction("SHA256"); + HashFunction hashFunc = Crypto.getHashFunction("SHA256"); HashDigest contentHash = hashFunc.hash("contentHash".getBytes()); HashDigest blockHash = hashFunc.hash("blockHash".getBytes()); long blockHeight = 9998L; diff --git a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Query_Test_.java b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Query_Test_.java index 6a2596ad..937b4604 100644 --- a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Query_Test_.java +++ b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Query_Test_.java @@ -13,7 +13,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.crypto.PubKey; @@ -176,12 +176,12 @@ public class SDK_GateWay_Query_Test_ { } private HashDigest getLedgerHash() { - HashDigest ledgerHash = CryptoServiceProviders.getHashFunction("SHA256").hash("jd-gateway".getBytes()); + HashDigest ledgerHash = Crypto.getHashFunction("SHA256").hash("jd-gateway".getBytes()); return ledgerHash; } private SignatureFunction getSignatureFunction() { - return CryptoServiceProviders.getSignatureFunction("ED25519"); + return Crypto.getSignatureFunction("ED25519"); } private BlockchainKeypair getSponsorKey() { @@ -193,7 +193,7 @@ public class SDK_GateWay_Query_Test_ { } private TransactionResponse initResponse() { - HashFunction hashFunc = CryptoServiceProviders.getHashFunction("SHA256"); + HashFunction hashFunc = Crypto.getHashFunction("SHA256"); HashDigest contentHash = hashFunc.hash("contentHash".getBytes()); HashDigest blockHash = hashFunc.hash("blockHash".getBytes()); long blockHeight = 9998L; diff --git a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_User_Test_.java b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_User_Test_.java index 463741c2..382466e9 100644 --- a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_User_Test_.java +++ b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_User_Test_.java @@ -15,7 +15,7 @@ import org.junit.Test; import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.crypto.PrivKey; @@ -138,12 +138,12 @@ public class SDK_GateWay_User_Test_ { // } private AsymmetricKeypair getSponsorKey() { - SignatureFunction signatureFunction = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519"); return signatureFunction.generateKeypair(); } private TransactionResponse initResponse() { - HashFunction hashFunc = CryptoServiceProviders.getHashFunction("SHA256");; + HashFunction hashFunc = Crypto.getHashFunction("SHA256");; HashDigest contentHash = hashFunc.hash("contentHash".getBytes()); HashDigest blockHash = hashFunc.hash("blockHash".getBytes()); long blockHeight = 9998L; diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java index 8abcdeea..fb64faec 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java @@ -15,7 +15,7 @@ import com.jd.blockchain.consensus.ConsensusProviders; import com.jd.blockchain.consensus.ConsensusSettings; import com.jd.blockchain.crypto.AddressEncoding; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.PubKey; @@ -616,7 +616,7 @@ public class IntegrationTest { // 验证合约中的赋值,外部可以获得; DataAccountSet dataAccountSet = ledgerOfNode0.getDataAccountSet(backgroundLedgerBlock); - AsymmetricKeypair key = CryptoServiceProviders.getSignatureFunction("ED25519").generateKeypair(); + AsymmetricKeypair key = Crypto.getSignatureFunction("ED25519").generateKeypair(); PubKey pubKey = key.getPubKey(); Bytes dataAddress = AddressEncoding.generateAddress(pubKey); diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeTest.java index 2a79f663..9a5cbd36 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeTest.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeTest.java @@ -13,7 +13,7 @@ import com.jd.blockchain.consensus.ConsensusProviders; import com.jd.blockchain.consensus.ConsensusSettings; import com.jd.blockchain.crypto.AddressEncoding; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.PubKey; @@ -217,7 +217,7 @@ public class LedgerInitializeTest { CryptoConfig cryptoSetting = new CryptoConfig(); cryptoSetting.setAutoVerifyHash(autoVerifyHash); - cryptoSetting.setHashAlgorithm(CryptoServiceProviders.getAlgorithm("SHA256")); + cryptoSetting.setHashAlgorithm(Crypto.getAlgorithm("SHA256")); partiKey = new AsymmetricKeypair(setting.getConsensusParticipant(0).getPubKey(), privKey); diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeWebTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeWebTest.java index 71d51286..c131930e 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeWebTest.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeWebTest.java @@ -14,7 +14,7 @@ import com.jd.blockchain.consensus.ConsensusProvider; import com.jd.blockchain.consensus.ConsensusProviders; import com.jd.blockchain.consensus.ConsensusSettings; import com.jd.blockchain.crypto.AddressEncoding; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.PubKey; @@ -223,7 +223,7 @@ public class LedgerInitializeWebTest { public SignatureDigest signPermissionRequest(int requesterId, PrivKey privKey, LedgerInitProperties initSetting) { byte[] reqAuthBytes = BytesUtils.concat(BytesUtils.toBytes(requesterId), initSetting.getLedgerSeed()); - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signFunc = Crypto.getSignatureFunction("ED25519"); SignatureDigest reqAuthSign = signFunc.sign(privKey, reqAuthBytes); return reqAuthSign; } diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java index c383217c..d2e13f49 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java @@ -18,7 +18,7 @@ import com.jd.blockchain.consensus.ConsensusProviders; import com.jd.blockchain.consensus.ConsensusSettings; import com.jd.blockchain.crypto.CryptoAlgorithm; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.ledger.BlockchainIdentity; @@ -110,8 +110,8 @@ public class LedgerPerformanceTest { dbType = DBType.ROCKSDB; } - CryptoAlgorithm hashAlg = ArgumentSet.hasOption(args, "-160") ? CryptoServiceProviders.getAlgorithm("RIPEMD260") - : CryptoServiceProviders.getAlgorithm("SHA256"); + CryptoAlgorithm hashAlg = ArgumentSet.hasOption(args, "-160") ? Crypto.getAlgorithm("RIPEMD260") + : Crypto.getAlgorithm("SHA256"); System.out.println( String.format("----- LedgerPerformanceTest [HashAlgorithm=%s][DBType=%s] ----", hashAlg, dbType)); // 初始化,并获取其中一个节点的账本,单独进行性能测试; diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/Utils.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/Utils.java index 96064d80..27d67e1a 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/Utils.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/Utils.java @@ -12,7 +12,7 @@ import com.jd.blockchain.consensus.ConsensusProvider; import com.jd.blockchain.consensus.ConsensusSettings; import com.jd.blockchain.crypto.CryptoAlgorithm; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.SignatureDigest; @@ -125,7 +125,7 @@ public class Utils { public AsyncCallback startInit(int currentId, PrivKey privKey, LedgerInitProperties setting, ConsensusSettings csProps, ConsensusProvider consensusProvider, DBConnectionConfig dbConnConfig, Prompter prompter, boolean autoVerifyHash) { - CryptoAlgorithm algorithm = CryptoServiceProviders.getAlgorithm("SHA256"); + CryptoAlgorithm algorithm = Crypto.getAlgorithm("SHA256"); return startInit(currentId, privKey, setting, csProps, consensusProvider, dbConnConfig, prompter, autoVerifyHash, algorithm); } diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestAll4Redis.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestAll4Redis.java index e8940d17..bcd2ca80 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestAll4Redis.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestAll4Redis.java @@ -16,7 +16,7 @@ import org.springframework.core.io.ClassPathResource; import com.jd.blockchain.crypto.AddressEncoding; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.PubKey; @@ -474,7 +474,7 @@ public class IntegrationTestAll4Redis { // 验证合约中的赋值,外部可以获得; DataAccountSet dataAccountSet = ledgerRepository.getDataAccountSet(backgroundLedgerBlock); - AsymmetricKeypair key = CryptoServiceProviders.getSignatureFunction("ED25519").generateKeypair(); + AsymmetricKeypair key = Crypto.getSignatureFunction("ED25519").generateKeypair(); PubKey pubKey = key.getPubKey(); Bytes dataAddress = AddressEncoding.generateAddress(pubKey); assertEquals(dataAddress, dataAccountSet.getDataAccount(dataAddress).getAddress()); diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/batch/bftsmart/BftsmartTestBase.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/batch/bftsmart/BftsmartTestBase.java index 05424499..f94f9364 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/batch/bftsmart/BftsmartTestBase.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/batch/bftsmart/BftsmartTestBase.java @@ -14,7 +14,7 @@ import static com.jd.blockchain.tools.keygen.KeyGenCommand.encodePubKey; import org.junit.Test; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.SignatureFunction; import com.jd.blockchain.utils.codec.Base58Utils; import com.jd.blockchain.utils.security.ShaUtils; @@ -36,7 +36,7 @@ public class BftsmartTestBase { @Test public void newUsers() { - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction("ED25519"); + SignatureFunction signFunc = Crypto.getSignatureFunction("ED25519"); for (int i = 0; i < userSize; i++) { AsymmetricKeypair kp = signFunc.generateKeypair(); diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeTest.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeTest.java index f0ab90ae..e96d3c18 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeTest.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeTest.java @@ -20,7 +20,7 @@ import com.jd.blockchain.consensus.ConsensusSettings; import com.jd.blockchain.crypto.AddressEncoding; import com.jd.blockchain.crypto.CryptoAlgorithm; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.PubKey; @@ -256,7 +256,7 @@ public class LedgerInitializeTest { CryptoConfig cryptoSetting = new CryptoConfig(); cryptoSetting.setAutoVerifyHash(autoVerifyHash); - cryptoSetting.setHashAlgorithm(CryptoServiceProviders.getAlgorithm("SHA256")); + cryptoSetting.setHashAlgorithm(Crypto.getAlgorithm("SHA256")); partiKey = new AsymmetricKeypair(setting.getConsensusParticipant(0).getPubKey(), privKey); diff --git a/source/test/test-ledger-core/src/main/java/test/perf/com/jd/blockchain/ledger/core/MerkleDatasetPerformanceTester.java b/source/test/test-ledger-core/src/main/java/test/perf/com/jd/blockchain/ledger/core/MerkleDatasetPerformanceTester.java index b7ea8df2..ef2f6064 100644 --- a/source/test/test-ledger-core/src/main/java/test/perf/com/jd/blockchain/ledger/core/MerkleDatasetPerformanceTester.java +++ b/source/test/test-ledger-core/src/main/java/test/perf/com/jd/blockchain/ledger/core/MerkleDatasetPerformanceTester.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Random; import com.jd.blockchain.crypto.CryptoAlgorithm; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.ledger.core.CryptoConfig; import com.jd.blockchain.ledger.core.MerkleDataSet; @@ -132,7 +132,7 @@ public class MerkleDatasetPerformanceTester { Random rand = new Random(); CryptoConfig cryptoConfig = new CryptoConfig(); - cryptoConfig.setHashAlgorithm(CryptoServiceProviders.getAlgorithm("SHA256")); + cryptoConfig.setHashAlgorithm(Crypto.getAlgorithm("SHA256")); cryptoConfig.setAutoVerifyHash(true); // generate base data sample; diff --git a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitializeWebController.java b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitializeWebController.java index 30c5d286..1bbf595f 100644 --- a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitializeWebController.java +++ b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitializeWebController.java @@ -20,7 +20,7 @@ import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.consensus.ConsensusProvider; import com.jd.blockchain.consensus.ConsensusSettings; import com.jd.blockchain.crypto.CryptoAlgorithm; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.PubKey; @@ -116,12 +116,12 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI private InitConsensusServiceFactory initCsServiceFactory; public LedgerInitializeWebController() { - this.SIGN_FUNC = CryptoServiceProviders.getSignatureFunction(DEFAULT_SIGN_ALGORITHM); + this.SIGN_FUNC = Crypto.getSignatureFunction(DEFAULT_SIGN_ALGORITHM); } public LedgerInitializeWebController(LedgerManage ledgerManager, DbConnectionFactory dbConnFactory, InitConsensusServiceFactory initCsServiceFactory) { - this.SIGN_FUNC = CryptoServiceProviders.getSignatureFunction(DEFAULT_SIGN_ALGORITHM); + this.SIGN_FUNC = Crypto.getSignatureFunction(DEFAULT_SIGN_ALGORITHM); this.ledgerManager = ledgerManager; this.dbConnFactory = dbConnFactory; @@ -301,7 +301,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI public CryptoSetting createDefaultCryptoSetting() { CryptoConfig defCryptoSetting = new CryptoConfig(); defCryptoSetting.setAutoVerifyHash(true); - defCryptoSetting.setHashAlgorithm(CryptoServiceProviders.getAlgorithm("SHA256")); + defCryptoSetting.setHashAlgorithm(Crypto.getAlgorithm("SHA256")); return defCryptoSetting; } @@ -376,7 +376,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI private LedgerInitDecision makeDecision(int participantId, HashDigest ledgerHash, PrivKey privKey) { byte[] dataBytes = getDecisionBytes(participantId, ledgerHash); - SignatureFunction signFunc = CryptoServiceProviders.getSignatureFunction(privKey.getAlgorithm()); + SignatureFunction signFunc = Crypto.getSignatureFunction(privKey.getAlgorithm()); SignatureDigest signature = signFunc.sign(privKey, dataBytes); LedgerInitDecisionData decision = new LedgerInitDecisionData(); diff --git a/source/tools/tools-keygen/src/main/java/com/jd/blockchain/tools/keygen/KeyGenCommand.java b/source/tools/tools-keygen/src/main/java/com/jd/blockchain/tools/keygen/KeyGenCommand.java index 845d9b6b..e0c63a0b 100644 --- a/source/tools/tools-keygen/src/main/java/com/jd/blockchain/tools/keygen/KeyGenCommand.java +++ b/source/tools/tools-keygen/src/main/java/com/jd/blockchain/tools/keygen/KeyGenCommand.java @@ -9,7 +9,7 @@ import java.util.List; import javax.crypto.SecretKey; import com.jd.blockchain.crypto.AsymmetricKeypair; -import com.jd.blockchain.crypto.CryptoServiceProviders; +import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.utils.ArgumentSet; @@ -114,7 +114,7 @@ public class KeyGenCommand { * @param outputDir */ private static void generateKeyPair(String name, String outputDir, String localConfPath) { - AsymmetricKeypair kp = CryptoServiceProviders.getSignatureFunction("ED25519").generateKeypair(); + AsymmetricKeypair kp = Crypto.getSignatureFunction("ED25519").generateKeypair(); String base58PubKey = encodePubKey(kp.getPubKey());