use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.
the class X509CertTest method convertPublicKeyToX509Key.
public static X509Key convertPublicKeyToX509Key(PublicKey pubk) throws Exception {
X509Key xKey = null;
if (pubk instanceof RSAPublicKey) {
RSAPublicKey rsaKey = (RSAPublicKey) pubk;
xKey = new org.mozilla.jss.netscape.security.provider.RSAPublicKey(new BigInt(rsaKey.getModulus()), new BigInt(rsaKey.getPublicExponent()));
} else if (pubk instanceof PK11ECPublicKey) {
byte[] encoded = pubk.getEncoded();
xKey = X509Key.parse(new DerValue(encoded));
}
return xKey;
}
use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.
the class StringTestUtil method normalizeUnicode.
public static byte[] normalizeUnicode(byte[] data) throws Exception {
try (DerOutputStream os = new DerOutputStream()) {
DerValue value = new DerValue(data);
byte[] tmp = value.data.toByteArray();
if (tmp[0] == -2 && tmp[1] == -1) {
// remove optional big-endian byte-order mark
byte tag = value.tag;
int length = value.length() - 2;
os.putTag((byte) 0, false, tag);
os.putLength(length);
os.write(tmp, 2, length);
return os.toByteArray();
}
return data;
}
}
use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.
the class EmptyDerValue method main.
public static void main(String[] args) throws Exception {
byte[] bytes = { 0x04, 0x00 };
DerValue derVal = new DerValue(bytes);
System.out.println(derVal.getOctetString());
}
use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.
the class EnumerationZeroTest method outputExtension.
/**
* Output the DER encoding of a CRLExtension for examination
*/
public static void outputExtension(CRLReasonExtension ext) throws Exception {
ByteArrayOutputStream resultBytesOut = new ByteArrayOutputStream();
ext.encode(resultBytesOut);
byte[] encodedBytes = resultBytesOut.toByteArray();
System.out.print("Full encoded extension: " + toHex(encodedBytes));
Extension reasonExt = new Extension(new DerValue(encodedBytes));
System.out.print("\tEncoded CRL Reason: " + toHex(reasonExt.getExtensionValue()));
DerValue reasonValue = new DerValue(reasonExt.getExtensionValue());
System.out.println("\tReason value: " + reasonValue.getEnumerated());
}
use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.
the class X509CertImpl method decode.
/**
* Decode an X.509 certificate from an input stream.
*
* @param in an input stream holding at least one certificate
* @exception CertificateException on parsing errors.
* @exception IOException on other errors.
*/
public void decode(InputStream in) throws CertificateException, IOException {
DerValue val = new DerValue(in);
parse(val);
signedCert = val.toByteArray();
}
Aggregations