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

crypto-formats.com.unbound.common.crypto.PKCS8 Maven / Gradle / Ivy

Go to download

This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi

There is a newer version: 42761
Show newest version
package com.unbound.common.crypto;

import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.RSAPrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;

public class PKCS8
{
  public static byte[] exportECPrivateKey(ECPrivateKey ec)
  {
    return ec.getEncoded();
  }

  public static ECPrivateKey importECPrivateKey(byte[] der)
  {
    try { return (ECPrivateKey) SystemProvider.KeyFactory.getInstance("EC").generatePrivate(new PKCS8EncodedKeySpec(der)); }
    catch (InvalidKeySpecException e) { throw new IllegalArgumentException(e); }
  }

  public static byte[] exportRSAPrivateKey(RSAPrivateKey rsa)
  {
    return rsa.getEncoded();
  }

  public static RSAPrivateKey importRSAPrivateKey(byte[] der)
  {
    try { return (RSAPrivateKey) SystemProvider.KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(der)); }
    catch (InvalidKeySpecException e) { throw new IllegalArgumentException(e); }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy