JAVA SM2加解密


import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.SM2;
	



public static void main(String[] args) {

	static String privateKeyHex = "8C999F68A39D70607A4F1F7E9A20F336F7D21679357B8E0D79A688C47DED18AC";
	static String x = "0C2872EE56C4E85B102D164F24C1DB718097C969EDC707FD65FFD07D628CD454";
	static String y = "C3AE1BB7CD0787E316F4A4876B273BA680CB601EDA75EB984A154939C6B5C3CE";
	static SM2 sm2 = new SM2(privateKeyHex,
			x,
			y);
			
	String aaa = "MDRENUYzQ0I5QkI0ODQyNDU2QTQ2ODNCQzI2MjMwNkFFMDk4RDY4MjVENjJBNjI2Q0YyRkYwNTY3MTJFOUE2NDJEQkE1MzlDOUUzQzRGQTcyNjlBMjZCRjVDMkRENDA4RDkzRTI2Q0E5QjYxQjVEODcxODZCMEM0Qjk3NUVDMjIxNTk4ODI2OURFODUwODRCMTg2N0Q2ODJCM0JDQUE5MENERjQ2RTVGODRDOTYyNjVGOTU5N0VCMjVGNDZFQzVGRkU4NDk4MzlGQkZFNDY1MjA0QjUzQzU5ODEzMTZCN0IwOUNGRjRDQjdFMDgwQjc3ODE2MDkxRDVENkEwNTQ4MjkxNzUzMTExRTQ5MjQ3NTQ2RTNGMDg5MkM5OEY2QkI0RkI5MzI3NDhENzg1NEI3NkI2ODE5MQ=%3D";
	
	System.out.println("原文:"+aaa );

	String sm2encoderparam= sm2.encryptBcd(aaa, KeyType.PublicKey);
	System.out.println("加密"+sm2encoderparam);
		
	byte[] result = sm2.decryptFromBcd(sm2encoderparam, KeyType.PrivateKey);
	String sm2decoderparam = StrUtil.str(result,"UTF-8");
	System.out.println("解密"+sm2decoderparam);	
		
	}
	
	

你可能感兴趣的:(#,JAVA,java,开发语言)