• 大小: 4KB
    文件类型: .java
    金币: 1
    下载: 0 次
    发布日期: 2021-05-23
  • 语言: Java
  • 标签: SM2Engine  

资源简介

共享基于国密算法SM2加、解密相关代码,有利于各程序员参考代码实现SM2加解密(BC实现)。

资源截图

代码片段和文件信息

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

评论

共有 条评论

相关资源