22
33import static org .junit .Assert .assertArrayEquals ;
44import static org .junit .Assert .assertEquals ;
5+ import static org .tron .common .utils .client .utils .AbiUtil .generateOccupationConstantPrivateKey ;
56
67import java .math .BigInteger ;
78import java .security .SignatureException ;
2021 */
2122public class BouncyCastleTest {
2223
23- private String privString = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4" ;
24- private BigInteger privateKey = new BigInteger (privString , 16 );
24+ // For safety reasons, test with a placeholder private key
25+ private final String privString = generateOccupationConstantPrivateKey ();
26+ private final BigInteger privateKey = new BigInteger (privString , 16 );
2527
2628 @ Test
2729 public void testHex () {
28- String spongyAddress = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826 " ;
30+ String spongyAddress = "2e988a386a799f506693793c6a5af6b54dfaabfb " ;
2931 ECKey key = ECKey .fromPrivate (privateKey );
3032 byte [] address = key .getAddress ();
3133 assertEquals (spongyAddress ,
@@ -55,10 +57,9 @@ public void testSha3Hash() {
5557
5658 @ Test
5759 public void testECKeyAddress () {
58- String spongyPubkey =
59- "040947751e3022ecf3016be03ec77ab0ce3c2662b4843898cb068d74f698ccc8ad75"
60- + "aa17564ae80a20bb044ee7a6d903e8e8df624b089c95d66a0570f051e5a05b" ;
61- String spongyAddress = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826" ;
60+ String spongyPubkey = "04e90c7d3640a1568839c31b70a893ab6714ef8415b9de90cedfc1c8f353a6983e625529"
61+ + "392df7fa514bdd65a2003f6619567d79bee89830e63e932dbd42362d34" ;
62+ String spongyAddress = "2e988a386a799f506693793c6a5af6b54dfaabfb" ;
6263 ECKey key = ECKey .fromPrivate (privateKey );
6364 byte [] pubkey = key .getPubKey ();
6465 assertEquals (spongyPubkey , Hex .toHexString (pubkey ));
@@ -71,7 +72,7 @@ public void testECKeyAddress() {
7172 public void testECKeySignature () throws SignatureException {
7273 SignInterface sign = SignUtils .fromPrivate (Hex .decode (privString ), true );
7374 String msg = "transaction raw data" ;
74- String spongyAddress = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826 " ;
75+ String spongyAddress = "2e988a386a799f506693793c6a5af6b54dfaabfb " ;
7576 byte [] hash = Sha256Hash .hash (true , msg .getBytes ());
7677 String sig = sign .signHash (hash );
7778 byte [] address = SignUtils .signatureToAddress (hash , sig , true );
@@ -102,9 +103,9 @@ public void testSM3Hash() {
102103
103104 @ Test
104105 public void testSM2Address () {
105- String spongyPublickey = "04f9539070c135be6183cbff4539f8298755df5981022769cd16cfdcb917fa7e32 "
106- + "4e83b50f0bdbb34acd6ccbb78d45a8a383403f26bbd03805a178c43407dfdeae " ;
107- String spongyAddress = "7dc44d739a5226c0d3037bb7919f653eb2f938b9 " ;
106+ String spongyPublickey = "04dc3547dbbc4c90a9cde599848e26cb145e805b3d11daaf9daae0680d9c6824058ac "
107+ + "35ddecb12f3a8bbc3104a2b91a2b7d04851d773d9b4ab8d5e0359243c8628 " ;
108+ String spongyAddress = "6cb22f88564bdd61eb4cdb36215add53bc702ff1 " ;
108109 SM2 key = SM2 .fromPrivate (privateKey );
109110 assertEquals (spongyPublickey , Hex .toHexString (key .getPubKey ()));
110111 byte [] address = key .getAddress ();
@@ -115,7 +116,7 @@ public void testSM2Address() {
115116 public void testSM2Signature () throws SignatureException {
116117 SignInterface sign = SignUtils .fromPrivate (Hex .decode (privString ), false );
117118 String msg = "transaction raw data" ;
118- String spongyAddress = "7dc44d739a5226c0d3037bb7919f653eb2f938b9 " ;
119+ String spongyAddress = "6cb22f88564bdd61eb4cdb36215add53bc702ff1 " ;
119120 byte [] hash = Sha256Hash .hash (false , msg .getBytes ());
120121 String sig = sign .signHash (hash );
121122 byte [] address = SignUtils .signatureToAddress (hash , sig , false );
0 commit comments