Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8822459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:06:44+00:00 2026-06-14T06:06:44+00:00

We trying to interface with a PIV smart card on iphone. We have the

  • 0

We trying to interface with a PIV smart card on iphone. We have the necessary libraries loaded and can send commands. Using a combination of get data and get response commands we are able to retrieve all the relevant certificates from the smart card. We are now trying to send general authenticate command to sign some data but receiving 6A80 . We are chaining this command. The first part of chain executes successfully with return code 90 00 but second command gives 6a80.

Our card description says

  1. RSA PKCS #1 v 1.5 with SHA-256 signatures
  2. RSA 2048 bit keys

We are hashing our data with SHA1 256 and padding it with pkcs v 1.5 padding . We have also encoded the hash with DER encoding. But either ways (with or without der encoding) we receive 6a80 error. Here is our code,

// gets data signed from the smart card
-(void) signData:(unsigned char *)origdata:(int) origdatalen:(int) key_reference :(int)        key_size:(int) hash_reference
{
    bool debug=false;
    unsigned char * encodedandpadded;
unsigned char * digest;
NSMutableString* cplc = [[NSMutableString alloc]init];
int derHeaderLen=0;
int keyModulo=0;
int digestLen=0;
if (key_size==2048){
    keyModulo=256;
} else if (key_size==1024){
    keyModulo=128;
}
unsigned char * derHeader=nil;

switch (hash_reference){

    case SHA1:
        derHeaderLen=15;
        derHeader=(unsigned char *) calloc(derHeaderLen,sizeof(unsigned char));
        derHeader[0]=0x30;
        derHeader[1]=0x21;
        derHeader[2]=0x30;
        derHeader[3]=0x09;
        derHeader[4]=0x06;
        derHeader[5]=0x05;
        derHeader[6]=0x2b;
        derHeader[7]=0x0e;
        derHeader[8]=0x03;
        derHeader[9]=0x02;
        derHeader[10]=0x1a;
        derHeader[11]=0x05;
        derHeader[12]=0x00;
        derHeader[13]=0x04;
        derHeader[14]=0x14;
        digestLen=CC_SHA1_DIGEST_LENGTH;
        digest = (unsigned char*) calloc(digestLen,sizeof(unsigned char));
        CC_SHA1(origdata, origdatalen,digest);

        break;
    case SHA256:
        derHeaderLen=19;
        derHeader=(unsigned char *) calloc(derHeaderLen,sizeof(unsigned char));
        derHeader[0]=0x30;
        derHeader[1]=0x31;
        derHeader[2]=0x30;
        derHeader[3]=0x09;
        derHeader[4]=0x06;
        derHeader[5]=0x09;
        derHeader[6]=0x60;
        derHeader[7]=0x86;
        derHeader[8]=0x48;
        derHeader[9]=0x01;
        derHeader[10]=0x65;
        derHeader[11]=0x03;
        derHeader[12]=0x04;
        derHeader[13]=0x02;
        derHeader[14]=0x01;
        derHeader[15]=0x05;
        derHeader[16]=0x00;
        derHeader[17]=0x04;
        derHeader[18]=0x20;
        digestLen=CC_SHA256_DIGEST_LENGTH;
        digest = (unsigned char*) calloc(digestLen,sizeof(unsigned char));
        CC_SHA256(origdata, origdatalen,digest);

        break;
    case SHA512:
        derHeaderLen=19;
        derHeader=(unsigned char *) calloc(derHeaderLen,sizeof(unsigned char));
        derHeader[0]=0x30;
        derHeader[1]=0x51;
        derHeader[2]=0x30;
        derHeader[3]=0x09;
        derHeader[4]=0x06;
        derHeader[5]=0x09;
        derHeader[6]=0x60;
        derHeader[7]=0x86;
        derHeader[8]=0x48;
        derHeader[9]=0x01;
        derHeader[10]=0x65;
        derHeader[11]=0x03;
        derHeader[12]=0x04;
        derHeader[13]=0x02;
        derHeader[14]=0x03;
        derHeader[15]=0x05;
        derHeader[16]=0x00;
        derHeader[17]=0x04;
        derHeader[18]=0x40;

        break;
    default:

        break;

}

   // {0x00, 0x01, PS, 0x00, T},
   bool derEncoding=true;
int psLen;
int finalLen;
if (derEncoding){
    psLen=keyModulo-3-(derHeaderLen+digestLen);
    finalLen=3+psLen+derHeaderLen+digestLen;

} else {
   psLen=keyModulo-3-(digestLen);
   finalLen=3+psLen+digestLen;
}
    encodedandpadded =(unsigned char *) calloc(finalLen,sizeof(unsigned char));
    int count=0;
    encodedandpadded[count++]=0x00;
    encodedandpadded[count++]=0x01;
   for (int i=0;i<psLen;i++){
       encodedandpadded[count++]=0xFF;
   }
   encodedandpadded[count++]=0x00;
   if (derEncoding) {
    for (int i=0;i<derHeaderLen;i++){
        encodedandpadded[count++]=derHeader[i];
    }
}

for (int i=0;i<digestLen;i++){
    encodedandpadded[count++]=digest[i];
}

if (debug){
     [cplc appendString:[NSString stringWithFormat:@" psLen=%d derHeaderLen=%d digestlent=%d finalLen=%d count=%d",psLen,derHeaderLen,digestLen,finalLen,count]];
    for (int i=0;i<finalLen;i++){
         [cplc appendString:[NSString stringWithFormat:@" %02x ",encodedandpadded[i]]];
    }
    [self printData:cplc];
}


[self generalAuthenticate:encodedandpadded :256];


}   


- (void) generalAuthenticate:(unsigned char *) paddeddata:(int) paddeddatalen{

bool debug=true;



PBSmartcardStatus result;

// the first command in the chain , we will send first 128 bytes in this command
unsigned char dat[] = {0x10, 0x87, 0x07, 0x9C};
NSMutableData * prepCommand1 = [[NSMutableData alloc] initWithBytes:dat length:4];
unsigned char dat2[] = {0x86,0x7C,0x84};
[prepCommand1 appendBytes:dat2 length:3];
unsigned char dat3[] = {0x82,0x00,0x81,0x80};
[prepCommand1 appendBytes:dat3 length:4];

unsigned char * part1 =(unsigned char *) calloc((paddeddatalen/2),sizeof(unsigned char));
unsigned char * part2=(unsigned char *) calloc((paddeddatalen/2),sizeof(unsigned char));
int count=0;
for(int i=0;i<(paddeddatalen/2);i++){
    part1[i]=paddeddata[count++];
}

[prepCommand1 appendBytes:part1 length:(paddeddatalen/2)];
for(int i=0;i<(paddeddatalen/2);i++){
    part2[i]=paddeddata[count++];
}
//the second command in the chain, we will send rest of 128 bytes in this command
unsigned char dat4[]={0x00, 0x87, 0x07, 0x9C, 0x80};
NSMutableData * prepCommand2 = [[NSMutableData alloc] initWithBytes:dat4 length:5];

[prepCommand2 appendBytes:part2 length:(paddeddatalen/2)];

unsigned char dat5[]={0x00};
[prepCommand2 appendBytes:dat5 length:1];



//unsigned char get_cplc_command[] = {0x10, 0x87, 0x07, 0x9C,(macOut.length+4),0x82,0x00,0x81,macOut.length};

NSMutableString* cplc = [[NSMutableString alloc]init];

unsigned char received_data[255] = {0};
unsigned short received_data_length;


// on input received_data_length holds the size of the receive buffer.
received_data_length = sizeof(received_data);
unsigned char * prepCmd1=(unsigned char *)[prepCommand1 bytes];
int prepCmd1Len=[prepCommand1 length];
// send the command APDU and get the response from the card.
if (debug){
    [cplc appendString:[NSString stringWithFormat:@"Length %d %d",prepCmd1Len,(paddeddatalen/2), count]];
    [self printData:cplc];
    for (int i=0;i<prepCmd1Len;i++){
            [cplc appendString:[NSString stringWithFormat:@"%02x",prepCmd1[i]]];
    }
    [self printData:cplc];

}
result = [smartcard transmit:prepCmd1
           withCommandLength:prepCmd1Len

           andResponseBuffer:received_data
           andResponseLength:&received_data_length];

LOG(@"transmit = %d", result);


// check if the command was succefully sent to the card
//    if(result != PBSmartcardStatusSuccess)
//    {
//        goto done;
//    }
if (debug){
[cplc appendString:[NSString stringWithFormat:@"Response bytes from card for general authenticate command %02X %02X length %d\n",received_data[received_data_length-2],received_data[received_data_length-1],received_data_length]];
[self printData:cplc];
}

unsigned char received_data_2[300] = {0};
unsigned short received_data_length_2;


// on input received_data_length holds the size of the receive buffer.
received_data_length_2 = sizeof(received_data_2);
unsigned char * prepCmd2=(unsigned char *)[prepCommand2 bytes];
int prepCmd2Len=[prepCommand2 length];
// send the command APDU and get the response from the card.
if (debug){
    [cplc appendString:[NSString stringWithFormat:@"Length %d",prepCmd2Len]];
    [self printData:cplc];
    for (int i=0;i<prepCmd2Len;i++){
        [cplc appendString:[NSString stringWithFormat:@"%02x",prepCmd2[i]]];
    }
    [self printData:cplc];

}
result = [smartcard transmit:prepCmd2
           withCommandLength:prepCmd2Len

           andResponseBuffer:received_data_2
           andResponseLength:&received_data_length_2];

if (debug){
    [cplc appendString:[NSString stringWithFormat:@"Response bytes from card for general authenticate command %02X %02X length %d\n",received_data_2[received_data_length_2-2],received_data_2[received_data_length_2-1],received_data_length_2]];
    [self printData:cplc];
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:06:45+00:00Added an answer on June 14, 2026 at 6:06 am

    Send only the hash value in the command data field instead of the PKCS#1 padded hash value. The card will likely do the padding as part of the signature operation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to design my app's interface in IB using a storyboard and have
I have a C++ DLL that I am trying to interface with using C#.
I am trying to have interface for C++ library for python using boost::python ,
I have been trying the following interface IUIntegral : IEquatable<Byte>, IEquatable<UInt16>, IEquatable<UInt32>, IEquatable<UInt64> {
I am trying to create an interface of the FileStream.Open method. I have started
I'm trying to get the Global Interface Table by using the following code (Delphi):
I am trying to define interface types in C++ using abstract classes and implement
I am trying to make a callback interface between C# and Java using JNA.
Am trying to create a tabbed interface in which the tabs can be visible
I'm trying to interface with the Google Reader (undocumented/unofficial) API using information from this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.