org.bouncycastle.pqc.jcajce.provider.util.KeyUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-ext-jdk15on Show documentation
Show all versions of bcprov-ext-jdk15on Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8. Note: this package includes the NTRU encryption algorithms.
package org.bouncycastle.pqc.jcajce.provider.util;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
public class KeyUtil
{
public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, ASN1Encodable keyData)
{
try
{
return getEncodedSubjectPublicKeyInfo(new SubjectPublicKeyInfo(algId, keyData));
}
catch (Exception e)
{
return null;
}
}
public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, byte[] keyData)
{
try
{
return getEncodedSubjectPublicKeyInfo(new SubjectPublicKeyInfo(algId, keyData));
}
catch (Exception e)
{
return null;
}
}
public static byte[] getEncodedSubjectPublicKeyInfo(SubjectPublicKeyInfo info)
{
try
{
return info.getEncoded(ASN1Encoding.DER);
}
catch (Exception e)
{
return null;
}
}
public static byte[] getEncodedPrivateKeyInfo(AlgorithmIdentifier algId, ASN1Encodable privKey)
{
try
{
PrivateKeyInfo info = new PrivateKeyInfo(algId, privKey.toASN1Primitive());
return getEncodedPrivateKeyInfo(info);
}
catch (Exception e)
{
return null;
}
}
public static byte[] getEncodedPrivateKeyInfo(PrivateKeyInfo info)
{
try
{
return info.getEncoded(ASN1Encoding.DER);
}
catch (Exception e)
{
return null;
}
}
}