-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update version to 5.1.13, support SM2.
- Loading branch information
1 parent
c980917
commit 169ff54
Showing
9 changed files
with
125 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/other/SM2Push.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cn.jiguang.sdk.bean.push.other; | ||
|
||
import cn.jiguang.sdk.bean.push.PushSendParam; | ||
import cn.jiguang.sdk.bean.push.audience.Audience; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class SM2Push { | ||
|
||
/** | ||
* 两种格式 | ||
* 字符串:"all" | ||
* {@link Audience}对象: {"tag":[],"tag_and":[],"tag_not":[],"alias":[],"registration_id":[],"segment":[],"abtest":[],"live_activity_id":"","file":{"file_id":""}} | ||
*/ | ||
@JsonProperty("audience") | ||
private Object audience; | ||
|
||
/** | ||
* 完整的消息体 | ||
*/ | ||
@JsonProperty("payload") | ||
private String payload; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
jiguang-sdk/src/main/java/cn/jiguang/sdk/utils/SM2Util.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cn.jiguang.sdk.utils; | ||
|
||
import org.bouncycastle.asn1.gm.GMNamedCurves; | ||
import org.bouncycastle.asn1.x9.X9ECParameters; | ||
import org.bouncycastle.crypto.engines.SM2Engine; | ||
import org.bouncycastle.crypto.params.ECDomainParameters; | ||
import org.bouncycastle.crypto.params.ECPublicKeyParameters; | ||
import org.bouncycastle.crypto.params.ParametersWithRandom; | ||
import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
import org.bouncycastle.math.ec.ECPoint; | ||
import org.bouncycastle.math.ec.custom.gm.SM2P256V1Curve; | ||
|
||
import java.security.SecureRandom; | ||
import java.security.Security; | ||
import java.util.Base64; | ||
|
||
public class SM2Util { | ||
|
||
static { | ||
Security.addProvider(new BouncyCastleProvider()); | ||
} | ||
|
||
private static final String BASE64_PUBLIC_KEY = "BPj6Mj/T444gxPaHc6CDCizMRp4pEl14WI2lvIbdEK2c+5XiSqmQt2TQc8hMMZqfxcDqUNQW95puAfQx1asv3rU="; | ||
|
||
private static final ECPublicKeyParameters PUBLIC_KEY = initializePublicKey(); | ||
|
||
private static ECPublicKeyParameters initializePublicKey() { | ||
X9ECParameters sm2Params = GMNamedCurves.getByName("sm2p256v1"); | ||
ECDomainParameters ecDomainParameters = new ECDomainParameters( | ||
sm2Params.getCurve(), | ||
sm2Params.getG(), | ||
sm2Params.getN(), | ||
sm2Params.getH() | ||
); | ||
SM2P256V1Curve CURVE = new SM2P256V1Curve(); | ||
ECPoint ecPoint = CURVE.decodePoint(Base64.getDecoder().decode(BASE64_PUBLIC_KEY)); | ||
return new ECPublicKeyParameters(ecPoint, ecDomainParameters); | ||
} | ||
|
||
public static byte[] encrypt(String plainText) throws Exception { | ||
SM2Engine engine = new SM2Engine(); | ||
engine.init(true, new ParametersWithRandom(PUBLIC_KEY, new SecureRandom())); | ||
byte[] plainBytes = plainText.getBytes(); | ||
return engine.processBlock(plainBytes, 0, plainBytes.length); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters