use of com.github.zhenwei.core.asn1.ASN1Primitive in project gdmatrix by gdmatrix.
the class P7MUtils method printAttribute.
public static void printAttribute(Attribute attribute) throws Exception {
ASN1Set set = attribute.getAttrValues();
ASN1Primitive der = set.getObjectAt(0).toASN1Primitive();
System.out.println(der.getClass());
if (der instanceof DEROctetString) {
DEROctetString octet = (DEROctetString) der;
byte[] data = octet.getOctets();
System.out.println(new String(data, "UTF-16LE"));
} else if (der instanceof ASN1UTCTime) {
ASN1UTCTime utcTime = (ASN1UTCTime) der;
String time = utcTime.getAdjustedTime();
System.out.println(time);
} else if (der instanceof ASN1ObjectIdentifier) {
ASN1ObjectIdentifier id = (ASN1ObjectIdentifier) der;
System.out.println(id.getId());
}
}
use of com.github.zhenwei.core.asn1.ASN1Primitive in project jiguang-java-client-common by jpush.
the class BCECUtil method convertECPrivateKeyToSEC1.
/**
* 将ECC私钥转换为SEC1标准的字节流
* openssl d2i_ECPrivateKey函数要求的DER编码的私钥也是SEC1标准的,
* 这个工具函数的主要目的就是为了能生成一个openssl可以直接“识别”的ECC私钥.
* 相对RSA私钥的PKCS1标准,ECC私钥的标准为SEC1
*
* @param priKey
* @param pubKey
* @return
* @throws IOException
*/
public static byte[] convertECPrivateKeyToSEC1(ECPrivateKeyParameters priKey, ECPublicKeyParameters pubKey) throws IOException {
byte[] pkcs8Bytes = convertECPrivateKeyToPKCS8(priKey, pubKey);
PrivateKeyInfo pki = PrivateKeyInfo.getInstance(pkcs8Bytes);
ASN1Encodable encodable = pki.parsePrivateKey();
ASN1Primitive primitive = encodable.toASN1Primitive();
byte[] sec1Bytes = primitive.getEncoded();
return sec1Bytes;
}
use of com.github.zhenwei.core.asn1.ASN1Primitive in project java-webauthn-server by Yubico.
the class ExtensionMatcher method matches.
@Override
public boolean matches(X509Certificate attestationCertificate, JsonNode parameters) {
String matchKey = parameters.get(EXTENSION_KEY).asText();
JsonNode matchValue = parameters.get(EXTENSION_VALUE);
byte[] extensionValue = attestationCertificate.getExtensionValue(matchKey);
if (extensionValue != null) {
if (matchValue == null) {
return true;
} else {
try {
final ASN1Primitive value = ASN1Primitive.fromByteArray(extensionValue);
if (matchValue.isObject()) {
if (matchTypedValue(matchKey, matchValue, value)) {
return true;
}
} else if (matchValue.isTextual()) {
if (matchStringValue(matchKey, matchValue, value))
return true;
}
} catch (IOException e) {
log.error("Failed to parse extension value as ASN1: {}", new ByteArray(extensionValue).getHex(), e);
}
}
}
return false;
}
use of com.github.zhenwei.core.asn1.ASN1Primitive in project SAMLRaider by CompassSecurity.
the class BurpCertificate method getAuthorityKeyIdentifier.
public String getAuthorityKeyIdentifier() {
byte[] e = certificate.getExtensionValue(Extension.authorityKeyIdentifier.getId());
if (e == null) {
return "";
}
ASN1Primitive ap;
byte[] k = {};
try {
ap = JcaX509ExtensionUtils.parseExtensionValue(e);
k = ASN1Sequence.getInstance(ap.getEncoded()).getEncoded();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Extension :(
return CertificateHelper.addHexColons(CertificateHelper.byteArrayToHex(k)).substring(12, k.length * 3 - 1);
}
use of com.github.zhenwei.core.asn1.ASN1Primitive in project CipherTrust_Application_Protection by thalescpl-io.
the class ByokSample method readAWSPublicKeyFromFile.
private static byte[] readAWSPublicKeyFromFile(String publicKeyPath) throws Exception {
File file = new File(publicKeyPath);
FileInputStream ios = new FileInputStream(file);
byte[] buffer = new byte[(int) file.length()];
try {
ios.read(buffer);
} finally {
ios.close();
}
// format conversion to PEM encoded PKCS#1 to allow import on to
// keysecure
X509EncodedKeySpec spec1 = new X509EncodedKeySpec(buffer);
KeyFactory kf1 = KeyFactory.getInstance("RSA");
RSAPublicKey pubKey = (RSAPublicKey) kf1.generatePublic(spec1);
byte[] pubBytes = pubKey.getEncoded();
SubjectPublicKeyInfo spkInfo = SubjectPublicKeyInfo.getInstance(pubBytes);
ASN1Primitive primitive = spkInfo.parsePublicKey();
if (primitive != null)
return primitive.getEncoded();
return null;
}
Aggregations