public class SM2KeyExchangeUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
private static boolean |
DEBUG |
private static byte[] |
DEFAULT_ID |
| 构造器和说明 |
|---|
SM2KeyExchangeUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
private static byte[] |
concat(BigInteger xV,
BigInteger yV,
byte[] ZA,
byte[] ZB,
boolean active) |
private static byte[] |
convertToBytes(BigInteger val)
BigInteger convert to byte[]
If bytes.length is less than 32 , the preceding 32-bytes.length bytes are filled with 0.
|
private static byte[] |
convertToBytes(BigInteger val,
int m) |
static org.bouncycastle.jce.interfaces.ECPublicKey |
generatePublicKey(org.bouncycastle.jce.interfaces.ECPrivateKey privateKey)
Generate public key by ECPrivateKey
|
static org.bouncycastle.math.ec.ECPoint |
generateR(org.bouncycastle.jce.interfaces.ECPublicKey publicKey,
BigInteger random)
R = [r] * G
|
static BigInteger |
generateRandom(BigInteger n,
SecureRandom secureRandom) |
static BigInteger |
generateRandom(org.bouncycastle.jce.interfaces.ECPublicKey publicKey,
SecureRandom secureRandom) |
static byte[] |
generateSharedSecret(org.bouncycastle.jce.interfaces.ECPublicKey localPublicKey,
org.bouncycastle.jce.interfaces.ECPrivateKey localPrivateKey,
BigInteger localRandom,
byte[] localId,
org.bouncycastle.jce.interfaces.ECPublicKey peerPublicKey,
byte[] peerRBytes,
byte[] peerId,
int secretLen,
boolean active) |
static byte[] |
generateZ(byte[] idBytes,
org.bouncycastle.jce.interfaces.ECPublicKey publicKey,
MessageDigest messageDigest)
Z = hash(
idLenBytes || idBytes ||
(32bytes)a || (32bytes) b || (32bytes)gX || (32bytes)gY || (32bytes)qX || (32bytes) qY)
)
|
private static void |
intToBytes(byte[] iBytes,
int num) |
static byte[] |
KDF(byte[] bytes,
int keyLength,
MessageDigest messageDigest) |
public static byte[] generateSharedSecret(org.bouncycastle.jce.interfaces.ECPublicKey localPublicKey,
org.bouncycastle.jce.interfaces.ECPrivateKey localPrivateKey,
BigInteger localRandom,
byte[] localId,
org.bouncycastle.jce.interfaces.ECPublicKey peerPublicKey,
byte[] peerRBytes,
byte[] peerId,
int secretLen,
boolean active)
throws IOException,
NoSuchAlgorithmException
public static org.bouncycastle.math.ec.ECPoint generateR(org.bouncycastle.jce.interfaces.ECPublicKey publicKey,
BigInteger random)
publicKey - random - public static BigInteger generateRandom(org.bouncycastle.jce.interfaces.ECPublicKey publicKey, SecureRandom secureRandom)
public static BigInteger generateRandom(BigInteger n, SecureRandom secureRandom)
public static byte[] generateZ(byte[] idBytes,
org.bouncycastle.jce.interfaces.ECPublicKey publicKey,
MessageDigest messageDigest)
idBytes - idpublicKey - SM2 PublicKeymessageDigest - SM3 digestpublic static byte[] KDF(byte[] bytes,
int keyLength,
MessageDigest messageDigest)
private static void intToBytes(byte[] iBytes,
int num)
private static byte[] concat(BigInteger xV, BigInteger yV, byte[] ZA, byte[] ZB, boolean active) throws IOException
IOExceptionprivate static byte[] convertToBytes(BigInteger val)
If the length is greater than or equal to 32 ,keep the last 32-bit byte. The format is as follows: bytes[bytes.length-32] ... bytes[bytes.length-1]
val - BigIntegerprivate static byte[] convertToBytes(BigInteger val, int m)
public static org.bouncycastle.jce.interfaces.ECPublicKey generatePublicKey(org.bouncycastle.jce.interfaces.ECPrivateKey privateKey)
throws InvalidKeyException
privateKey - InvalidKeyExceptionCopyright © 2022. All rights reserved.