I wanted to change the OID of the SubjectPublicKeyInfo in CSR. But i am getting both OIDs in the CSR the specific one and the Built in one.
// Use Bouncy Castle to create a CSR with attributes and a common name
PKCS10CertificationRequestBuilder csrBuilder = new PKCS10CertificationRequestBuilder (
X500Name.getInstance(AsnToDerEncoding.createSubject()),
subjectPublicKeyInfo
);
ASN1ObjectIdentifier objId = new ASN1ObjectIdentifier("Specific OID");
AlgorithmIdentifier algId = new AlgorithmIdentifier(objId);
ASN1BitString derBitString = new DERBitString(keyPair.getPublic().getEncoded());
SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algId, derBitString);
It's changing the OID but the built-in function takes the particular OID of the public key and gives both the OIDs in the CertificateRequestInfo, and I need only the specific one. CSRDecoded
Java
PublicKey.getEncoded()returns the SPKI (SubjectPublicKeyInfo) structure including the algorithmid containing the standard OID; thus when you put this in the bitstring (data) part of a second SPKI you got a nested structure with two OIDs.You apparently want to parse the first SPKI to extract only the data part, and use that, which you can do with the same BouncyCastle class: