![JAR search and dependency download from the Maven repository](/logo.png)
crypto-formats.com.unbound.common.crypto.PKCS8 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unbound-java-provider Show documentation
Show all versions of unbound-java-provider Show documentation
This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi
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