Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.security.KeyFactory;

import java.security.NoSuchAlgorithmException;

import java.security.interfaces.DSAPrivateKey;

import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;

public class Main {
    public static DSAPrivateKey getDSAPriKeyfromEncoded(byte[] encKey)
            throws NoSuchAlgorithmException, InvalidKeySpecException {
        PKCS8EncodedKeySpec pubKeySpec = new PKCS8EncodedKeySpec(encKey);
        KeyFactory kf = KeyFactory.getInstance("DSA");
        return (DSAPrivateKey) kf.generatePrivate(pubKeySpec);
    }
}