use of com.android.apksig.internal.x509.SubjectPublicKeyInfo in project modules by assimbly.
the class CertificatesUtil method createAuthorityKeyId.
/**
* Creates the hash value of the authority public key.
*
* @param publicKey of the authority certificate
*
* @return AuthorityKeyIdentifier hash
*
* @throws OperatorCreationException
*/
private static AuthorityKeyIdentifier createAuthorityKeyId(final PublicKey publicKey) throws OperatorCreationException {
final SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo.getInstance(publicKey.getEncoded());
final DigestCalculator digCalc = new BcDigestCalculatorProvider().get(new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1));
return new X509ExtensionUtils(digCalc).createAuthorityKeyIdentifier(publicKeyInfo);
}
use of com.android.apksig.internal.x509.SubjectPublicKeyInfo in project modules by assimbly.
the class CertificatesUtil method createSubjectKeyId.
/**
* Creates the hash value of the public key.
*
* @param publicKey of the certificate
*
* @return SubjectKeyIdentifier hash
*
* @throws OperatorCreationException
*/
private static SubjectKeyIdentifier createSubjectKeyId(final PublicKey publicKey) throws OperatorCreationException {
final SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo.getInstance(publicKey.getEncoded());
final DigestCalculator digCalc = new BcDigestCalculatorProvider().get(new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1));
return new X509ExtensionUtils(digCalc).createSubjectKeyIdentifier(publicKeyInfo);
}
use of com.android.apksig.internal.x509.SubjectPublicKeyInfo in project nosql-java-sdk by oracle.
the class DriverTestBase method generateKeyPair.
/**
* Generate a RAS key and certificate, return in PEM. Note that certificate
* must has OU with opc-tenant:TestTenant, because it's used by instance
* and resource principal testing.
* @return a string that the first element is key and the second one is
* certificate.
*/
protected static KeyPairInfo generateKeyPair() throws Exception {
KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
keygen.initialize(2048);
KeyPair keypair = keygen.generateKeyPair();
JcaPKCS8Generator gen = new JcaPKCS8Generator(keypair.getPrivate(), null);
StringWriter sw = new StringWriter();
try (JcaPEMWriter pw = new JcaPEMWriter(sw)) {
pw.writeObject(gen.generate());
}
String key = sw.toString();
X500Name name = new X500Name("OU=opc-tenant:TestTenant");
SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(keypair.getPublic().getEncoded());
Date start = new Date();
Date until = Date.from(LocalDate.now().plus(3650, ChronoUnit.DAYS).atStartOfDay().toInstant(ZoneOffset.UTC));
X509v3CertificateBuilder builder = new X509v3CertificateBuilder(name, new BigInteger(10, new SecureRandom()), start, until, name, subPubKeyInfo);
ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSA").setProvider(new BouncyCastleProvider()).build(keypair.getPrivate());
X509CertificateHolder holder = builder.build(signer);
Certificate cert = new JcaX509CertificateConverter().setProvider(new BouncyCastleProvider()).getCertificate(holder);
sw = new StringWriter();
try (JcaPEMWriter pw = new JcaPEMWriter(sw)) {
pw.writeObject(cert);
}
String certString = sw.toString();
return new KeyPairInfo(key, certString, keypair);
}
use of com.android.apksig.internal.x509.SubjectPublicKeyInfo in project tutorials by csh0034.
the class RsaUtils method convertPkcs1PemToPublicKey.
public static PublicKey convertPkcs1PemToPublicKey(InputStream is) {
try {
PEMParser pemParser = new PEMParser(new InputStreamReader(Objects.requireNonNull(is)));
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME);
SubjectPublicKeyInfo publicKeyInfo = (SubjectPublicKeyInfo) pemParser.readObject();
return converter.getPublicKey(publicKeyInfo);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.android.apksig.internal.x509.SubjectPublicKeyInfo in project axelor-open-suite by axelor.
the class X509Generator method getAuthorityKeyIdentifier.
/**
* Returns the <code>AuthorityKeyIdentifier</code> corresponding to a given <code>PublicKey</code>
*
* @param publicKey the given public key
* @param issuer the certificate issuer
* @param serial the certificate serial number
* @return the authority key identifier of the public key
* @throws IOException
*/
private AuthorityKeyIdentifier getAuthorityKeyIdentifier(PublicKey publicKey, String issuer, BigInteger serial) throws IOException {
InputStream input;
SubjectPublicKeyInfo keyInfo;
ASN1EncodableVector vector;
input = new ByteArrayInputStream(publicKey.getEncoded());
try (final ASN1InputStream is = new ASN1InputStream(input)) {
keyInfo = SubjectPublicKeyInfo.getInstance((ASN1Sequence) is.readObject());
}
vector = new ASN1EncodableVector();
vector.add(new GeneralName(new X509Name(issuer)));
return new AuthorityKeyIdentifier(keyInfo, GeneralNames.getInstance(new DERSequence(vector)), serial);
}
Aggregations