Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
JDChain
Explorer
提交
173e4ba7
E
Explorer
项目概览
JDChain
/
Explorer
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
Explorer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
173e4ba7
编写于
5月 15, 2019
作者:
H
huanghaiquan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed compiling error;
上级
8a4fdc3b
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
152 addition
and
129 deletion
+152
-129
source/crypto/crypto-classic/src/main/java/com/jd/blockchain/crypto/utils/classic/RSAUtils.java
...java/com/jd/blockchain/crypto/utils/classic/RSAUtils.java
+26
-15
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/AESEncryptionFunctionTest.java
...ain/crypto/service/classic/AESEncryptionFunctionTest.java
+5
-5
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ECDSASignatureFunctionTest.java
...in/crypto/service/classic/ECDSASignatureFunctionTest.java
+7
-7
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ED25519SignatureFunctionTest.java
.../crypto/service/classic/ED25519SignatureFunctionTest.java
+7
-7
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RIPEMD160HashFunctionTest.java
...ain/crypto/service/classic/RIPEMD160HashFunctionTest.java
+4
-4
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RSACryptoFunctionTest.java
...ckchain/crypto/service/classic/RSACryptoFunctionTest.java
+9
-9
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/SHA256HashFunctionTest.java
...kchain/crypto/service/classic/SHA256HashFunctionTest.java
+4
-4
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ECDSAUtilsTest.java
...om/jd/blockchain/crypto/utils/classic/ECDSAUtilsTest.java
+1
-1
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ED25519UtilsTest.java
.../jd/blockchain/crypto/utils/classic/ED25519UtilsTest.java
+1
-1
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/RSAUtilsTest.java
.../com/jd/blockchain/crypto/utils/classic/RSAUtilsTest.java
+3
-3
source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoAlgorithm.java
...c/main/java/com/jd/blockchain/crypto/CryptoAlgorithm.java
+8
-8
source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoBytesEncoding.java
...in/java/com/jd/blockchain/crypto/CryptoBytesEncoding.java
+1
-1
source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM2CyptoFunctionTest.java
...jd/blockchain/crypto/service/sm/SM2CyptoFunctionTest.java
+9
-9
source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM3HashFunctionTest.java
.../jd/blockchain/crypto/service/sm/SM3HashFunctionTest.java
+3
-3
source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM4EncryptionFunctionTest.java
...ockchain/crypto/service/sm/SM4EncryptionFunctionTest.java
+5
-5
source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/utils/SM2UtilsTest.java
...ava/test/com/jd/blockchain/crypto/utils/SM2UtilsTest.java
+43
-43
source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/CryptoProviderInfo.java
...ain/java/com/jd/blockchain/ledger/CryptoProviderInfo.java
+12
-0
source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ED25519SignatureTest.java
...t/com/jd/blockchain/ledger/data/ED25519SignatureTest.java
+1
-1
source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitSettingTest.java
...d/blockchain/intgr/initializer/LedgerInitSettingTest.java
+2
-2
source/test/test-integration/src/test/resources/ledger.init
source/test/test-integration/src/test/resources/ledger.init
+1
-1
未找到文件。
source/crypto/crypto-classic/src/main/java/com/jd/blockchain/crypto/utils/classic/RSAUtils.java
浏览文件 @
173e4ba7
package
com.jd.blockchain.crypto.utils.classic
;
import
com.jd.blockchain.utils.io.BytesUtils
;
import
org.bouncycastle.asn1.*
;
import
java.io.IOException
;
import
java.math.BigInteger
;
import
java.security.KeyFactory
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.SecureRandom
;
import
java.security.interfaces.RSAPrivateCrtKey
;
import
java.security.interfaces.RSAPublicKey
;
import
java.security.spec.InvalidKeySpecException
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
java.security.spec.X509EncodedKeySpec
;
import
org.bouncycastle.asn1.ASN1EncodableVector
;
import
org.bouncycastle.asn1.ASN1Encoding
;
import
org.bouncycastle.asn1.ASN1Integer
;
import
org.bouncycastle.asn1.ASN1Sequence
;
import
org.bouncycastle.asn1.DERNull
;
import
org.bouncycastle.asn1.DERSequence
;
import
org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers
;
import
org.bouncycastle.asn1.pkcs.RSAPrivateKey
;
import
org.bouncycastle.asn1.x509.AlgorithmIdentifier
;
import
org.bouncycastle.crypto.*
;
import
org.bouncycastle.crypto.AsymmetricBlockCipher
;
import
org.bouncycastle.crypto.AsymmetricCipherKeyPair
;
import
org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator
;
import
org.bouncycastle.crypto.CipherParameters
;
import
org.bouncycastle.crypto.CryptoException
;
import
org.bouncycastle.crypto.InvalidCipherTextException
;
import
org.bouncycastle.crypto.digests.SHA256Digest
;
import
org.bouncycastle.crypto.encodings.PKCS1Encoding
;
import
org.bouncycastle.crypto.engines.RSAEngine
;
...
...
@@ -16,17 +36,8 @@ import org.bouncycastle.crypto.params.RSAKeyParameters;
import
org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters
;
import
org.bouncycastle.crypto.signers.RSADigestSigner
;
import
org.bouncycastle.jcajce.provider.asymmetric.util.KeyUtil
;
import
sun.security.rsa.RSAPrivateCrtKeyImpl
;
import
java.io.IOException
;
import
java.math.BigInteger
;
import
java.security.KeyFactory
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.SecureRandom
;
import
java.security.interfaces.RSAPublicKey
;
import
java.security.spec.InvalidKeySpecException
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
java.security.spec.X509EncodedKeySpec
;
import
com.jd.blockchain.utils.io.BytesUtils
;
/**
* @author zhanglin33
...
...
@@ -442,9 +453,9 @@ public class RSAUtils {
throw
new
com
.
jd
.
blockchain
.
crypto
.
CryptoException
(
e
.
getMessage
(),
e
);
}
RSAPrivateCrtKey
Impl
privateKey
;
RSAPrivateCrtKey
privateKey
;
try
{
privateKey
=
(
RSAPrivateCrtKey
Impl
)
keyFactory
.
generatePrivate
(
keySpec
);
privateKey
=
(
RSAPrivateCrtKey
)
keyFactory
.
generatePrivate
(
keySpec
);
}
catch
(
InvalidKeySpecException
e
)
{
throw
new
com
.
jd
.
blockchain
.
crypto
.
CryptoException
(
e
.
getMessage
(),
e
);
}
...
...
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/AESEncryptionFunctionTest.java
浏览文件 @
173e4ba7
...
...
@@ -69,7 +69,7 @@ public class AESEncryptionFunctionTest {
assertEquals
(
algorithm
.
code
(),
symmetricKey
.
getAlgorithm
());
assertEquals
(
2
+
1
+
128
/
8
,
symmetricKey
.
toBytes
().
length
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
keyTypeBytes
=
new
byte
[]
{
SYMMETRIC
.
CODE
};
byte
[]
rawKeyBytes
=
symmetricKey
.
getRawKeyBytes
();
assertArrayEquals
(
BytesUtils
.
concat
(
algoBytes
,
keyTypeBytes
,
rawKeyBytes
),
symmetricKey
.
toBytes
());
...
...
@@ -167,7 +167,7 @@ public class AESEncryptionFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
symmetricKey
.
getRawKeyBytes
();
byte
[]
ripemd160KeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -197,7 +197,7 @@ public class AESEncryptionFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
symmetricKey
.
getRawKeyBytes
();
byte
[]
ripemd160KeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -235,7 +235,7 @@ public class AESEncryptionFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawCiphertextBytes
=
ciphertext
.
toBytes
();
byte
[]
ripemd160CiphertextBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawCiphertextBytes
);
...
...
@@ -275,7 +275,7 @@ public class AESEncryptionFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawCiphertextBytes
=
ciphertext
.
getRawCiphertext
();
byte
[]
ripemd160CiphertextBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawCiphertextBytes
);
...
...
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ECDSASignatureFunctionTest.java
浏览文件 @
173e4ba7
...
...
@@ -66,7 +66,7 @@ public class ECDSASignatureFunctionTest {
assertEquals
(
2
+
1
+
65
,
pubKey
.
toBytes
().
length
);
assertEquals
(
2
+
1
+
32
,
privKey
.
toBytes
().
length
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawPubKeyBytes
=
pubKey
.
getRawKeyBytes
();
...
...
@@ -162,7 +162,7 @@ public class ECDSASignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
privKey
.
getRawKeyBytes
();
byte
[]
ripemd160PubKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -194,7 +194,7 @@ public class ECDSASignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
privKey
.
getRawKeyBytes
();
byte
[]
ripemd160PubKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -227,7 +227,7 @@ public class ECDSASignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawKeyBytes
=
pubKey
.
getRawKeyBytes
();
byte
[]
ripemd160PrivKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
privKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -259,7 +259,7 @@ public class ECDSASignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawKeyBytes
=
pubKey
.
getRawKeyBytes
();
byte
[]
ripemd160PrivKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
privKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -298,7 +298,7 @@ public class ECDSASignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawDigestBytes
=
signatureDigest
.
toBytes
();
byte
[]
ripemd160SignatureBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
@@ -335,7 +335,7 @@ public class ECDSASignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawDigestBytes
=
signatureDigest
.
getRawDigest
();
byte
[]
ripemd160SignatureDigestBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ED25519SignatureFunctionTest.java
浏览文件 @
173e4ba7
...
...
@@ -93,7 +93,7 @@ public class ED25519SignatureFunctionTest {
assertEquals
(
2
+
1
+
32
,
pubKey
.
toBytes
().
length
);
assertEquals
(
2
+
1
+
32
,
privKey
.
toBytes
().
length
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawPubKeyBytes
=
pubKey
.
getRawKeyBytes
();
...
...
@@ -189,7 +189,7 @@ public class ED25519SignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
privKey
.
getRawKeyBytes
();
byte
[]
ripemd160PubKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -221,7 +221,7 @@ public class ED25519SignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
privKey
.
getRawKeyBytes
();
byte
[]
ripemd160PubKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -254,7 +254,7 @@ public class ED25519SignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawKeyBytes
=
pubKey
.
getRawKeyBytes
();
byte
[]
ripemd160PrivKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
privKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -286,7 +286,7 @@ public class ED25519SignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawKeyBytes
=
pubKey
.
getRawKeyBytes
();
byte
[]
ripemd160PrivKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
privKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -325,7 +325,7 @@ public class ED25519SignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawDigestBytes
=
signatureDigest
.
toBytes
();
byte
[]
ripemd160SignatureBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
@@ -362,7 +362,7 @@ public class ED25519SignatureFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawDigestBytes
=
signatureDigest
.
getRawDigest
();
byte
[]
ripemd160SignatureDigestBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RIPEMD160HashFunctionTest.java
浏览文件 @
173e4ba7
...
...
@@ -57,7 +57,7 @@ public class RIPEMD160HashFunctionTest {
HashDigest
digest
=
hashFunction
.
hash
(
data
);
byte
[]
rawDigestBytes
=
digest
.
getRawDigest
();
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
digestBytes
=
digest
.
toBytes
();
assertEquals
(
160
/
8
+
2
,
digestBytes
.
length
);
...
...
@@ -111,7 +111,7 @@ public class RIPEMD160HashFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"aes"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
System
.
arraycopy
(
algoBytes
,
0
,
digestBytes
,
0
,
algoBytes
.
length
);
assertFalse
(
hashFunction
.
supportHashDigest
(
digestBytes
));
}
...
...
@@ -140,7 +140,7 @@ public class RIPEMD160HashFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"aes"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawDigestBytes
=
digest
.
getRawDigest
();
byte
[]
aesDigestBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
@@ -156,7 +156,7 @@ public class RIPEMD160HashFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sha256"
);
assertNotNull
(
algorithm
);
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
rawDigestBytes
=
digest
.
getRawDigest
();
byte
[]
ripemd160DigestBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RSACryptoFunctionTest.java
浏览文件 @
173e4ba7
...
...
@@ -65,7 +65,7 @@ public class RSACryptoFunctionTest {
assertEquals
(
2
+
1
+
257
,
pubKey
.
toBytes
().
length
);
assertEquals
(
2
+
1
+
1153
,
privKey
.
toBytes
().
length
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawPubKeyBytes
=
pubKey
.
getRawKeyBytes
();
...
...
@@ -219,7 +219,7 @@ public class RSACryptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
privKey
.
getRawKeyBytes
();
byte
[]
ripemd160PubKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -251,7 +251,7 @@ public class RSACryptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
privKey
.
getRawKeyBytes
();
byte
[]
ripemd160PubKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -284,7 +284,7 @@ public class RSACryptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawKeyBytes
=
pubKey
.
getRawKeyBytes
();
byte
[]
ripemd160PrivKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
privKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -316,7 +316,7 @@ public class RSACryptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawKeyBytes
=
pubKey
.
getRawKeyBytes
();
byte
[]
ripemd160PrivKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
privKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -355,7 +355,7 @@ public class RSACryptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawDigestBytes
=
signatureDigest
.
toBytes
();
byte
[]
ripemd160SignatureBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
@@ -392,7 +392,7 @@ public class RSACryptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawDigestBytes
=
signatureDigest
.
getRawDigest
();
byte
[]
ripemd160SignatureDigestBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
@@ -432,7 +432,7 @@ public class RSACryptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawCiphertextBytes
=
ciphertext
.
toBytes
();
byte
[]
ripemd160CiphertextBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawCiphertextBytes
);
...
...
@@ -470,7 +470,7 @@ public class RSACryptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawCiphertextBytes
=
ciphertext
.
getRawCiphertext
();
byte
[]
ripemd160CiphertextBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawCiphertextBytes
);
...
...
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/SHA256HashFunctionTest.java
浏览文件 @
173e4ba7
...
...
@@ -57,7 +57,7 @@ public class SHA256HashFunctionTest {
HashDigest
digest
=
hashFunction
.
hash
(
data
);
byte
[]
rawDigestBytes
=
digest
.
getRawDigest
();
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
digestBytes
=
digest
.
toBytes
();
assertEquals
(
256
/
8
+
2
,
digestBytes
.
length
);
...
...
@@ -111,7 +111,7 @@ public class SHA256HashFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"aes"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
System
.
arraycopy
(
algoBytes
,
0
,
digestBytes
,
0
,
algoBytes
.
length
);
assertFalse
(
hashFunction
.
supportHashDigest
(
digestBytes
));
}
...
...
@@ -140,7 +140,7 @@ public class SHA256HashFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"aes"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawDigestBytes
=
digest
.
getRawDigest
();
byte
[]
aesDigestBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
@@ -156,7 +156,7 @@ public class SHA256HashFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"ripemd160"
);
assertNotNull
(
algorithm
);
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
rawDigestBytes
=
digest
.
getRawDigest
();
byte
[]
ripemd160DigestBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ECDSAUtilsTest.java
浏览文件 @
173e4ba7
...
...
@@ -146,7 +146,7 @@ public class ECDSAUtilsTest {
assertTrue
(
ECDSAUtils
.
verify
(
pubKey
,
signature
,
hashedMsg
));
}
@Test
//
@Test
public
void
performanceTest
(){
int
count
=
10000
;
...
...
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ED25519UtilsTest.java
浏览文件 @
173e4ba7
...
...
@@ -109,7 +109,7 @@ public class ED25519UtilsTest {
}
@Test
//
@Test
public
void
performanceTest
(){
int
count
=
10000
;
...
...
source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/RSAUtilsTest.java
浏览文件 @
173e4ba7
...
...
@@ -162,7 +162,7 @@ public class RSAUtilsTest {
}
@Test
//
@Test
public
void
performanceTest
(){
int
count
=
10000
;
...
...
@@ -228,7 +228,7 @@ public class RSAUtilsTest {
}
}
@Test
//
@Test
public
void
encryptionConsistencyTest
(){
int
count
=
10000
;
...
...
@@ -326,7 +326,7 @@ public class RSAUtilsTest {
assertArrayEquals
(
data
,
plaintext
);
}
@Test
//
@Test
public
void
signatureConsistencyTest
()
{
int
count
=
10000
;
...
...
source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoAlgorithm.java
浏览文件 @
173e4ba7
...
...
@@ -9,7 +9,7 @@ import com.jd.blockchain.binaryproto.PrimitiveType;
import
com.jd.blockchain.consts.DataCodes
;
import
com.jd.blockchain.utils.io.BytesUtils
;
@DataContract
(
code
=
DataCodes
.
CRYPTO_ALGORITHM
)
//
@DataContract(code = DataCodes.CRYPTO_ALGORITHM)
public
interface
CryptoAlgorithm
{
/**
...
...
@@ -51,7 +51,7 @@ public interface CryptoAlgorithm {
static
final
int
SYMMETRIC_KEY
=
0x0200
;
/**
* 算法编码的字节长度;等同于 {@link #
to
Bytes(CryptoAlgorithm)} 返回的字节数组的长度;
* 算法编码的字节长度;等同于 {@link #
getCode
Bytes(CryptoAlgorithm)} 返回的字节数组的长度;
*/
static
final
int
CODE_SIZE
=
2
;
...
...
@@ -63,7 +63,7 @@ public interface CryptoAlgorithm {
* {@link #EXT_ALGORITHM}) 5 种); 接下来4位标识密钥类型(包括:{@link #SYMMETRIC_KEY},
* {@link #ASYMMETRIC_KEY}); 最后8位是算法唯一ID;
*/
@DataField
(
primitiveType
=
PrimitiveType
.
INT16
,
order
=
0
)
//
@DataField(primitiveType = PrimitiveType.INT16, order = 0)
short
code
();
/**
...
...
@@ -81,16 +81,16 @@ public interface CryptoAlgorithm {
*
* @return
*/
static
byte
[]
to
Bytes
(
CryptoAlgorithm
algorithm
)
{
static
byte
[]
getCode
Bytes
(
CryptoAlgorithm
algorithm
)
{
return
BytesUtils
.
toBytes
(
algorithm
.
code
());
}
static
short
resolveCode
(
byte
[]
algorithm
Bytes
)
{
return
BytesUtils
.
toShort
(
algorithm
Bytes
,
0
);
static
short
resolveCode
(
byte
[]
code
Bytes
)
{
return
BytesUtils
.
toShort
(
code
Bytes
,
0
);
}
static
short
resolveCode
(
byte
[]
algorithm
Bytes
,
int
offset
)
{
return
BytesUtils
.
toShort
(
algorithm
Bytes
,
offset
);
static
short
resolveCode
(
byte
[]
code
Bytes
,
int
offset
)
{
return
BytesUtils
.
toShort
(
code
Bytes
,
offset
);
}
static
short
resolveCode
(
InputStream
in
)
{
...
...
source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoBytesEncoding.java
浏览文件 @
173e4ba7
...
...
@@ -10,7 +10,7 @@ public final class CryptoBytesEncoding {
}
static
byte
[]
encodeBytes
(
CryptoAlgorithm
algorithm
,
byte
[]
rawCryptoBytes
)
{
return
BytesUtils
.
concat
(
CryptoAlgorithm
.
to
Bytes
(
algorithm
),
rawCryptoBytes
);
return
BytesUtils
.
concat
(
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
),
rawCryptoBytes
);
}
public
static
short
decodeAlgorithm
(
byte
[]
cryptoBytes
)
{
...
...
source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM2CyptoFunctionTest.java
浏览文件 @
173e4ba7
...
...
@@ -65,7 +65,7 @@ public class SM2CyptoFunctionTest {
assertEquals
(
2
+
1
+
65
,
pubKey
.
toBytes
().
length
);
assertEquals
(
2
+
1
+
32
,
privKey
.
toBytes
().
length
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawPubKeyBytes
=
pubKey
.
getRawKeyBytes
();
...
...
@@ -219,7 +219,7 @@ public class SM2CyptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
privKey
.
getRawKeyBytes
();
byte
[]
sm3PubKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -251,7 +251,7 @@ public class SM2CyptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
privKey
.
getRawKeyBytes
();
byte
[]
sm3PubKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -284,7 +284,7 @@ public class SM2CyptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawKeyBytes
=
pubKey
.
getRawKeyBytes
();
byte
[]
sm3PrivKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
privKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -316,7 +316,7 @@ public class SM2CyptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
privKeyTypeBytes
=
new
byte
[]
{
PRIVATE
.
CODE
};
byte
[]
rawKeyBytes
=
pubKey
.
getRawKeyBytes
();
byte
[]
sm3PrivKeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
privKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -355,7 +355,7 @@ public class SM2CyptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawDigestBytes
=
signatureDigest
.
toBytes
();
byte
[]
sm3SignatureBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
@@ -392,7 +392,7 @@ public class SM2CyptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawDigestBytes
=
signatureDigest
.
getRawDigest
();
byte
[]
sm3SignatureDigestBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
@@ -432,7 +432,7 @@ public class SM2CyptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawCiphertextBytes
=
ciphertext
.
toBytes
();
byte
[]
sm3CiphertextBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawCiphertextBytes
);
...
...
@@ -470,7 +470,7 @@ public class SM2CyptoFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawCiphertextBytes
=
ciphertext
.
getRawCiphertext
();
byte
[]
sm3CiphertextBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawCiphertextBytes
);
...
...
source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM3HashFunctionTest.java
浏览文件 @
173e4ba7
...
...
@@ -55,7 +55,7 @@ public class SM3HashFunctionTest {
HashDigest
digest
=
hashFunction
.
hash
(
data
);
byte
[]
rawDigestBytes
=
digest
.
getRawDigest
();
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
digestBytes
=
digest
.
toBytes
();
assertEquals
(
256
/
8
+
2
,
digestBytes
.
length
);
...
...
@@ -109,7 +109,7 @@ public class SM3HashFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm4"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
System
.
arraycopy
(
algoBytes
,
0
,
digestBytes
,
0
,
algoBytes
.
length
);
assertFalse
(
hashFunction
.
supportHashDigest
(
digestBytes
));
}
...
...
@@ -138,7 +138,7 @@ public class SM3HashFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm4"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawDigestBytes
=
digest
.
getRawDigest
();
byte
[]
aesDigestBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawDigestBytes
);
...
...
source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM4EncryptionFunctionTest.java
浏览文件 @
173e4ba7
...
...
@@ -68,7 +68,7 @@ public class SM4EncryptionFunctionTest {
assertEquals
(
algorithm
.
code
(),
symmetricKey
.
getAlgorithm
());
assertEquals
(
2
+
1
+
128
/
8
,
symmetricKey
.
toBytes
().
length
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
keyTypeBytes
=
new
byte
[]
{
SYMMETRIC
.
CODE
};
byte
[]
rawKeyBytes
=
symmetricKey
.
getRawKeyBytes
();
assertArrayEquals
(
BytesUtils
.
concat
(
algoBytes
,
keyTypeBytes
,
rawKeyBytes
),
symmetricKey
.
toBytes
());
...
...
@@ -165,7 +165,7 @@ public class SM4EncryptionFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
symmetricKey
.
getRawKeyBytes
();
byte
[]
ripemd160KeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -194,7 +194,7 @@ public class SM4EncryptionFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
pubKeyTypeBytes
=
new
byte
[]
{
PUBLIC
.
CODE
};
byte
[]
rawKeyBytes
=
symmetricKey
.
getRawKeyBytes
();
byte
[]
ripemd160KeyBytes
=
BytesUtils
.
concat
(
algoBytes
,
pubKeyTypeBytes
,
rawKeyBytes
);
...
...
@@ -232,7 +232,7 @@ public class SM4EncryptionFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawCiphertextBytes
=
ciphertext
.
toBytes
();
byte
[]
sm3CiphertextBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawCiphertextBytes
);
...
...
@@ -268,7 +268,7 @@ public class SM4EncryptionFunctionTest {
algorithm
=
Crypto
.
getAlgorithm
(
"sm3"
);
assertNotNull
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
to
Bytes
(
algorithm
);
byte
[]
algoBytes
=
CryptoAlgorithm
.
getCode
Bytes
(
algorithm
);
byte
[]
rawCiphertextBytes
=
ciphertext
.
getRawCiphertext
();
byte
[]
sm3CiphertextBytes
=
BytesUtils
.
concat
(
algoBytes
,
rawCiphertextBytes
);
...
...
source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/utils/SM2UtilsTest.java
浏览文件 @
173e4ba7
...
...
@@ -119,50 +119,50 @@ public class SM2UtilsTest {
byte
[]
plaintext
=
SM2Utils
.
decrypt
(
ciphertext
,
privKeyBytes
);
assertArrayEquals
(
expectedMessage
.
getBytes
(),
plaintext
);
}
//
// @Test
public
void
encryptingPerformace
(){
byte
[]
data
=
new
byte
[
1000
];
Random
random
=
new
Random
();
random
.
nextBytes
(
data
);
int
count
=
10000
;
byte
[]
ciphertext
=
null
;
AsymmetricCipherKeyPair
keyPair
=
SM2Utils
.
generateKeyPair
();
ECPublicKeyParameters
ecPub
=
(
ECPublicKeyParameters
)
keyPair
.
getPublic
();
ECPrivateKeyParameters
ecPriv
=
(
ECPrivateKeyParameters
)
keyPair
.
getPrivate
();
System
.
out
.
println
(
"=================== do SM2 encrypt test ==================="
);
for
(
int
r
=
0
;
r
<
5
;
r
++)
{
System
.
out
.
println
(
"------------- round["
+
r
+
"] --------------"
);
long
startTS
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
ciphertext
=
SM2Utils
.
encrypt
(
data
,
ecPub
);
}
long
elapsedTS
=
System
.
currentTimeMillis
()
-
startTS
;
System
.
out
.
println
(
String
.
format
(
"SM2 Encrypting Count=%s; Elapsed Times=%s; KBPS=%.2f"
,
count
,
elapsedTS
,
(
count
*
1000.00
D
)
/
elapsedTS
));
}
System
.
out
.
println
(
"=================== do SM2 decrypt test ==================="
);
for
(
int
r
=
0
;
r
<
5
;
r
++)
{
System
.
out
.
println
(
"------------- round["
+
r
+
"] --------------"
);
long
startTS
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
SM2Utils
.
decrypt
(
ciphertext
,
ecPriv
);
}
long
elapsedTS
=
System
.
currentTimeMillis
()
-
startTS
;
System
.
out
.
println
(
String
.
format
(
"SM2 Decrypting Count=%s; Elapsed Times=%s; KBPS=%.2f"
,
count
,
elapsedTS
,
(
count
*
1000.00
D
)
/
elapsedTS
));
}
}
// @Test
// public void encryptingPerformace(){
//
// byte[] data = new byte[1000];
// Random random = new Random();
// random.nextBytes(data);
//
// int count = 10000;
//
// byte[] ciphertext = null;
//
// AsymmetricCipherKeyPair keyPair = SM2Utils.generateKeyPair();
// ECPublicKeyParameters ecPub = (ECPublicKeyParameters) keyPair.getPublic();
// ECPrivateKeyParameters ecPriv = (ECPrivateKeyParameters) keyPair.getPrivate();
//
// System.out.println("=================== do SM2 encrypt test ===================");
//
// for (int r = 0; r < 5; r++) {
// System.out.println("------------- round[" + r + "] --------------");
// long startTS = System.currentTimeMillis();
// for (int i = 0; i < count; i++) {
// ciphertext = SM2Utils.encrypt(data,ecPub);
// }
// long elapsedTS = System.currentTimeMillis() - startTS;
// System.out.println(String.format("SM2 Encrypting Count=%s; Elapsed Times=%s; KBPS=%.2f", count, elapsedTS,
// (count * 1000.00D) / elapsedTS));
// }
//
// System.out.println("=================== do SM2 decrypt test ===================");
// for (int r = 0; r < 5; r++) {
// System.out.println("------------- round[" + r + "] --------------");
// long startTS = System.currentTimeMillis();
// for (int i = 0; i < count; i++) {
// SM2Utils.decrypt(ciphertext,ecPriv);
// }
// long elapsedTS = System.currentTimeMillis() - startTS;
// System.out.println(String.format("SM2 Decrypting Count=%s; Elapsed Times=%s; KBPS=%.2f", count, elapsedTS,
// (count * 1000.00D) / elapsedTS));
// }
// }
//
//
@Test
public
void
signingPerformace
(){
byte
[]
data
=
new
byte
[
1024
];
...
...
source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/CryptoProviderInfo.java
0 → 100644
浏览文件 @
173e4ba7
package
com.jd.blockchain.ledger
;
import
com.jd.blockchain.crypto.CryptoAlgorithm
;
public
interface
CryptoProviderInfo
{
String
getName
();
CryptoAlgorithm
[]
getAlgorithms
();
}
source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ED25519SignatureTest.java
浏览文件 @
173e4ba7
...
...
@@ -11,7 +11,7 @@ import com.jd.blockchain.utils.security.Ed25519Utils;
public
class
ED25519SignatureTest
{
@Test
//
@Test
public
void
perfomanceTest
()
{
Random
rand
=
new
Random
();
byte
[]
data
=
new
byte
[
64
];
...
...
source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitSettingTest.java
浏览文件 @
173e4ba7
...
...
@@ -32,7 +32,7 @@ public class LedgerInitSettingTest {
ConsensusParticipantConfig
part0
=
setting
.
getConsensusParticipant
(
0
);
assertEquals
(
"jd.com"
,
part0
.
getName
());
assertEquals
(
"keys/jd-com.pub"
,
part0
.
getPubKeyPath
());
PubKey
pubKey0
=
KeyGenCommand
.
decodePubKey
(
"3snPdw7i7P
apsDoW185c3kfK6p8s6SwiJAdEUzgnfeuUox12nxgzXu
"
);
PubKey
pubKey0
=
KeyGenCommand
.
decodePubKey
(
"3snPdw7i7P
jVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9
"
);
assertEquals
(
pubKey0
,
part0
.
getPubKey
());
// assertEquals("127.0.0.1", part0.getConsensusAddress().getHost());
// assertEquals(8900, part0.getConsensusAddress().getPort());
...
...
@@ -43,7 +43,7 @@ public class LedgerInitSettingTest {
ConsensusParticipantConfig
part1
=
setting
.
getConsensusParticipant
(
1
);
assertEquals
(
false
,
part1
.
getInitializerAddress
().
isSecure
());
PubKey
pubKey1
=
KeyGenCommand
.
decodePubKey
(
"3snPdw7i7P
h1SYLQt9uqVEqiuvNXjxCdGvEdN6otJsg5rbr7Aze7kf
"
);
PubKey
pubKey1
=
KeyGenCommand
.
decodePubKey
(
"3snPdw7i7P
ajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX
"
);
assertEquals
(
pubKey1
,
part1
.
getPubKey
());
ConsensusParticipantConfig
part2
=
setting
.
getConsensusParticipant
(
2
);
...
...
source/test/test-integration/src/test/resources/ledger.init
浏览文件 @
173e4ba7
...
...
@@ -51,7 +51,7 @@ cons_parti.2.name=bt.com
#第2个参与方的公钥文件路径;
cons_parti.2.pubkey-path=keys/bt-com.pub
#第2个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数;
cons_parti.2.pubkey=
3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x
cons_parti.2.pubkey=
#第2个参与方的共识服务的主机地址;
cons_parti.2.consensus.host=127.0.0.1
#第2个参与方的共识服务的端口;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录