資源簡介
共享基于國密算法SM2加、解密相關(guān)代碼,有利于各程序員參考代碼實現(xiàn)SM2加解密(BC實現(xiàn))。
代碼片段和文件信息
package?com.szca.test;
import?java.math.BigInteger;
import?java.security.SecureRandom;
import?szca.org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import?szca.org.bouncycastle.crypto.engines.SM2Engine;
import?szca.org.bouncycastle.crypto.generators.ECKeyPairGenerator;
import?szca.org.bouncycastle.crypto.params.ECDomainParameters;
import?szca.org.bouncycastle.crypto.params.ECKeyGenerationParameters;
import?szca.org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import?szca.org.bouncycastle.crypto.params.ECPublicKeyParameters;
import?szca.org.bouncycastle.crypto.params.ParametersWithRandom;
import?szca.org.bouncycastle.math.ec.ECCurve;
import?szca.org.bouncycastle.math.ec.ECPoint;
import?szca.org.bouncycastle.util.Arrays;
import?szca.org.bouncycastle.util.Strings;
import?szca.org.bouncycastle.util.test.SimpleTest;
public?class?SM2EngineTest?extends?SimpleTest
{
??public?String?getName()
??{
????return?“SM2Engine“;
??}
??private?void?doEngineTestFp()
????throws?Exception
??{
????BigInteger?p?=?new?BigInteger(“FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF“?16);
????BigInteger?a?=?new?BigInteger(“FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC“?16);
????BigInteger?b?=?new?BigInteger(“28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93“?16);
????BigInteger?n?=?new?BigInteger(“FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123“?16);
????BigInteger?x?=?new?BigInteger(“32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7“?16);
????BigInteger?y?=?new?BigInteger(“BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0“?16);
????ECCurve.Fp?localFp?=?new?ECCurve.Fp(p?a?b);
????ECPoint?localECPoint?=?localFp.createPoint(x?y);
????ECDomainParameters?localECDomainParameters?=?new?ECDomainParameters(localFp?localECPoint?n);
????ECKeyPairGenerator?localECKeyPairGenerator?=?new?ECKeyPairGenerator();
????ECKeyGenerationParameters?localECKeyGenerationParameters?=?new?ECKeyGenerationParameters(localECDomainParameter
評論
共有 條評論