package com.hengyue.gmssl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Reference;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import java.util.Scanner;
/**
* Created by Mr.F on 2020/3/26.
*/
public class GmSSL {
private static byte[] sm2PrivateKey = new byte[] {
(byte)0x30,(byte)0x77,(byte)0x02,(byte)0x01,(byte)0x01,(byte)0x04,(byte)0x20,(byte)0x28,
(byte)0x7d,(byte)0x3f,(byte)0xb9,(byte)0xf4,(byte)0xbb,(byte)0xc8,(byte)0xbd,(byte)0xe1,
(byte)0x54,(byte)0x75,(byte)0x87,(byte)0x9f,(byte)0x08,(byte)0x61,(byte)0x20,(byte)0xe3,
(byte)0x65,(byte)0xf8,(byte)0xb2,(byte)0xca,(byte)0x14,(byte)0x26,(byte)0x81,(byte)0xf6,
(byte)0x1e,(byte)0xd8,(byte)0x7f,(byte)0xc0,(byte)0x66,(byte)0x20,(byte)0x29,(byte)0xa0,
(byte)0x0a,(byte)0x06,(byte)0x08,(byte)0x2a,(byte)0x81,(byte)0x1c,(byte)0xcf,(byte)0x55,
(byte)0x01,(byte)0x82,(byte)0x2d,(byte)0xa1,(byte)0x44,(byte)0x03,(byte)0x42,(byte)0x00,
(byte)0x04,(byte)0xb1,(byte)0x1e,(byte)0x4c,(byte)0x8c,(byte)0xa9,(byte)0x02,(byte)0xf2,
(byte)0x8d,(byte)0x8b,(byte)0x98,(byte)0xd2,(byte)0xd0,(byte)0xc4,(byte)0xf1,(byte)0x60,
(byte)0x91,(byte)0xfb,(byte)0x61,(byte)0x62,(byte)0x00,(byte)0xcf,(byte)0x93,(byte)0x4e,
(byte)0x3f,(byte)0xca,(byte)0xfd,(byte)0xf7,(byte)0x9d,(byte)0x76,(byte)0xb8,(byte)0x2b,
(byte)0xb3,(byte)0x30,(byte)0x98,(byte)0x65,(byte)0xf5,(byte)0x12,(byte)0xab,(byte)0x45,
(byte)0x78,(byte)0x29,(byte)0x87,(byte)0xdc,(byte)0x74,(byte)0x07,(byte)0x75,(byte)0xd0,
(byte)0x68,(byte)0xad,(byte)0x85,(byte)0x71,(byte)0x08,(byte)0xc2,(byte)0x19,(byte)0xf0,
(byte)0xf4,(byte)0xca,(byte)0x6e,(byte)0xe1,(byte)0xea,(byte)0x86,(byte)0xe6,(byte)0x21,
(byte)0x76};
private static byte[] sm2PublicKey = new byte[] {
(byte)0x30,(byte)0x59,(byte)0x30,(byte)0x13,(byte)0x06,(byte)0x07,(byte)0x2a,(byte)0x86,
(byte)0x48,(byte)0xce,(byte)0x3d,(byte)0x02,(byte)0x01,(byte)0x06,(byte)0x08,(byte)0x2a,
(byte)0x81,(byte)0x1c,(byte)0xcf,(byte)0x55,(byte)0x01,(byte)0x82,(byte)0x2d,(byte)0x03,
(byte)0x42,(byte)0x00,(byte)0x04,(byte)0xb1,(byte)0x1e,(byte)0x4c,(byte)0x8c,(byte)0xa9,
(byte)0x02,(byte)0xf2,(byte)0x8d,(byte)0x8b,(byte)0x98,(byte)0xd2,(byte)0xd0,(byte)0xc4,
(byte)0xf1,(byte)0x60,(byte)0x91,(byte)0xfb,(byte)0x61,(byte)0x62,(byte)0x00,(byte)0xcf,
(byte)0x93,(byte)0x4e,(byte)0x3f,(byte)0xca,(byte)0xfd,(byte)0xf7,(byte)0x9d,(byte)0x76,
(byte)0xb8,(byte)0x2b,(byte)0xb3,(byte)0x30,(byte)0x98,(byte)0x65,(byte)0xf5,(byte)0x12,
(byte)0xab,(byte)0x45,(byte)0x78,(byte)0x29,(byte)0x87,(byte)0xdc,(byte)0x74,(byte)0x07,
(byte)0x75,(byte)0xd0,(byte)0x68,(byte)0xad,(byte)0x85,(byte)0x71,(byte)0x08,(byte)0xc2,
(byte)0x19,(byte)0xf0,(byte)0xf4,(byte)0xca,(byte)0x6e,(byte)0xe1,(byte)0xea,(byte)0x86,
(byte)0xe6,(byte)0x21,(byte)0x76};
@Autowired
private static RedisTemplate<String,Object> redisTemplate;
static Scanner sc = new Scanner(System.in);
public static native String[] getVersions();
public static native String[] getCiphers();
public static native String[] getDigests();
public static native String[] getMacs();
public static native String[] getSignAlgorithms();
public static native String[] getPublicKeyEncryptions();
public static native String[] getDeriveKeyAlgorithms();
public static native byte[] generateRandom(int length);
public static native int getCipherIVLength(String cipher);
public static native int getCipherKeyLength(String cipher);
public static native int getCipherBlockSize(String cipher);
public static native byte[] symmetricEncrypt(String cipher, byte[] in, byte[] key, byte[] iv);
public static native byte[] symmetricDecrypt(String cipher, byte[] in, byte[] key, byte[] iv);
public static native int getDigestLength(String digest);
public static native int getDigestBlockSize(String digest);
public static native byte[] digest(String algor, byte[] data);
public static native String[] getMacLength(String algor);
public static native byte[] mac(String algor, byte[] data, byte[] key);
public static native byte[] sign(String algor, byte[] data, byte[] privateKey);
public static native int verify(String algor, byte[] digest, byte[] signature, byte[] publicKey);
public static native byte[] publicKeyEncrypt(String algor, byte[] in, byte[] publicKey);
public static native byte[] publicKeyDecrypt(String algor, byte[] in, byte[] privateKey);
public static native byte[] deriveKey(String algor, int keyLength, byte[] peerPublicKey, byte[] privateKey);
public static native String[] getErrorStrings();
/**
* 获取redis中私钥信息
* @return
public static byte[] getSm2PrivateKey(){
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
Object obj = redisTemplate.opsForValue().get("privateKey");
return "".getBytes();
} */
/**
* 获取redis中公钥信息
* @return
public static byte[] getSm2PublicKey(){
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
Object obj = redisTemplate.opsForValue().get("publicKey");
return "".getBytes();
}*/
static {
System.loadLibrary("gmssljni");
}
public static void main(String[] args) {
while (true) {
System.out.println("############GmsslAPI##############");
System.out.println("1. getVersions");//获取版本信息
System.out.println("2.generateRandom");//随机数生成
System.out.println("3.getCiphers");//获取密钥
System.out.println("4.getCipherIVLength");
System.out.println("5.getCipherKeyLength");//获取密钥长度
System.out.println("6.getCipherBlockSize");
System.out.println("7.symmetricEncrypt");//对称加密
System.out.println("8.symmetricDecrypt");//对称解密
System.out.println("9.getDigests");//获取摘要
System.out.println("10.getDigestLength");//获取摘要长度
System.out.println("11.getDigestBlockSize");
System.out.println("12.digest");//哈希
System.out.println("13.getMacs");//获取mac
System.out.println("14.getMacLength");//获取mac长度
System.out.println("15.mac");//生mac
System.out.println("16.getSignAlgorithms");
System.out.println("17.sign");//数字签名
System.out.println("18.verify");//验签
System.out.println("19.getPublicKeyEncryptions");//获取公钥
System.out.println("20.publicKeyEncrypt");//公钥加密
System.out.println("21.publicKeyDecrypt");//公钥解密
System.out.println("22.getDeriveKeyAlgorithms");
System.out.println("23.deriveKey");//密钥交换
System.out.println("24.getErrorString");//获取错误信息
System.out.println("##################################");
String[] s = null;
switch (sc.nextInt()) {
case 1:
String[] versions = getVersions();
for (int i = 0; i < versions.length; i++) {
System.out.println(versions[i]);
}
break;
case 2:
byte[] b = generateRandom(20);
for (int i = 0; i < b.length; i++) {
System.ou
java调用Gmssl国密接口实例
1星 需积分: 41 27 浏览量
2020-03-31
16:38:31
上传
评论 2
收藏 19KB ZIP 举报
不止会New
- 粉丝: 117
- 资源: 2
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈