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