标签 "java" 下的文章

问题:java提供的sm2公钥无法在python中使用

解决:因为java和python使用的加密方法有差

方法:

package com.bocsoft.security;
import com.bocsoft.decrypt.Util;
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import static com.bocsoft.decrypt.Util.getHexString;

public class translate {

    public static void main(String[] args) throws Exception {
        String private_key = "308193020100301306072a8648ce3d020106082a811ccf5501822d0479307702010104205931b7fa3a8ec4e974d48e84b8a64d931c9e7bad295dafe57940573d46481c44a00a06082a811ccf5501822da14403420004798718d3c2152a61ef18ff58adfb83e6694f84ea6c58ce4cfa83f79bb7ff4893d5e6050242cca375a6585f265bd862b448c90af4c61d67620900526f3ebffcaf";
        String public_key = "04251ed256cf8ac425443cc444cda5aafbe8aa22a5c5af1f11b2eecff6217bb3299e554c202f5253eee538ff1576bdba729e9a4d338508ba421b6c6330dca2711c";
        byte[] sm2_private = privateKey(Util.hexStringToBytes(private_key));
        System.out.println("私钥为:"+ Util.encodeHexString(sm2_private));

        byte[] publicKey = publicKey(Util.hexStringToBytes(public_key));
        System.out.println("公钥为: " + Util.encodeHexString(publicKey));
    }

阅读全文