0
//Android Java code
String OID_PKCS9_AT_MESSAGE_DIGEST = "1.2.840.113549.1.9.4";  
String hastosign  ="92a70799e19d8734fecfb8e59aa930e9f386f7645059a1f2f04eb8483c9b5f1d" \\Line 1
byte[] dataHash =  Hex.decode(hastosign)                                              \\Line 2

ASN1EncodableVector signedAttributesVector = new ASN1EncodableVector();

ASN1ObjectIdentifier aSN1ObjectIdentifierPKCS9MessageDigest = new 
ASN1ObjectIdentifier(OID_PKCS9_AT_MESSAGE_DIGEST);
DEROctetString dEROctetStringMessageDigest = new DEROctetString(dataHash);               
  \\Line 3
DERSet dERSetMessageDigest = new DERSet(dEROctetStringMessageDigest);       //Enclose into SET
Attribute cmsAttributeMessageDigest = new 
Attribute(aSN1ObjectIdentifierPKCS9MessageDigest, dERSetMessageDigest);
signedAttributesVector.add(cmsAttributeMessageDigest);



//Objective-c Code starts IOS

static uint8_t SEQUENCE_OBJECT_MessageDigest[] = {0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x04};

NSMutableData * contentInfo = [[NSMutableData alloc] init];

NSMutableData * msgdata = [NSMutableData dataWithCapacity:257]; 
[msgdata appendBytes:SEQUENCE_OBJECT_MessageDigest 
length:sizeof(SEQUENCE_OBJECT_MessageDigest)];
NSMutableData * msgdataValueResult = [NSMutableData dataWithCapacity:257];
NSMutableData * msgdataValue = [NSMutableData dataWithCapacity:257];
[msgdataValue appendBytes:sha_buffer length:sizeof(sha_buffer)]; \\Line 4
[self appendBITSTRING:msgdataValue into:msgdataValueResult];
[self enclose:msgdataValueResult by:SET_tag]; // Enclose into SET

[msgdata appendData:msgdataValueResult];
[self enclose:msgdata by:SEQUENCE_tag]; // Enclose into SEQUENCE

[contentInfo appendData:msgdata];


//appendBITSTRING method which we use to create octet string
   //OCTET String
    -(void)appendBITSTRING:(NSData *)data into:(NSMutableData *)into
    {
      char strtype = 0x04; //OCTET String
      [into appendBytes:&strtype length:1];
      [self appendDERLength:[data length] into:into];
      [into appendData:data];
    }

Question:

MessageDigest attribute contains attributeType and attributeValue where attributeType =aSN1ObjectIdentifierPKCS9MessageDigest and attributeValue = dERSetMessageDigest

In Android "dERSetMessageDigest" is an octetstring that we are generating DEROctetString of hastosign(\ Line 1) and including in message digest attribute value.

The same procudure we are doing in objective c. but facing difficulty to generate hastosign(Hexstring) to Hex.decode(hashtosing) (Line 1 to Line 2) in Objective c the resulted Hex.decode(hashtosing) suppose to sit in \Line 4

please assist us to convert below thing into Objective c

String hastosign ="92a70799e19d8734fecfb8e59aa930e9f386f7645059a1f2f04eb8483c9b5f1d" \\Line 1
byte[] dataHash =  Hex.decode(hastosign) \\Line 2
  • does this help? https://stackoverflow.com/questions/6421282/how-to-convert-hex-to-nsstring-in-objective-c#6421836 – battlmonstr Dec 28 '21 at 21:45
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 03 '22 at 11:51

0 Answers0