Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.math.BigInteger;
import java.security.Key;
import java.security.KeyFactory;

import java.security.spec.RSAPrivateKeySpec;

public class Main {
    public static Key getRSAKey(String hexModulus, String hexPrivateExponent) throws Exception {
        BigInteger m = new BigInteger(hexModulus, 16);
        BigInteger e = new BigInteger(hexPrivateExponent, 16);
        RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(m, e);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        Key rsaKey = keyFactory.generatePrivate(keySpec);
        return rsaKey;
    }
}