All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.t.util.security.message.digitalsign.ecdsa.EcdsaSignUtil Maven / Gradle / Ivy

There is a newer version: 1.0.16.RELEASE
Show newest version
package cn.t.util.security.message.digitalsign.ecdsa;

import cn.t.util.security.message.AlgorithmName;
import cn.t.util.security.message.AlgorithmUtil;

import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;

public class EcdsaSignUtil {

    public static PublicKey convertEncodedBytesToPublicKey(byte[] encodedBytes) throws NoSuchAlgorithmException, InvalidKeySpecException {
        X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(encodedBytes);
        KeyFactory keyFactory = AlgorithmUtil.generateKeyFactory(AlgorithmName.EC);
        return keyFactory.generatePublic(x509EncodedKeySpec);
    }

    public static PrivateKey convertEncodedBytesToPrivateKey(byte[] encodedBytes) throws NoSuchAlgorithmException, InvalidKeySpecException {
        PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(encodedBytes);
        KeyFactory keyFactory = AlgorithmUtil.generateKeyFactory(AlgorithmName.EC);
        return keyFactory.generatePrivate(pkcs8EncodedKeySpec);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy