Skip to content

signature not valid #9

@zealit

Description

@zealit

the CSR created by this code gives some error. When I verify the CSR (online) I get the messages:

  • signature not valid
  • Certificate Signing Request (CSR) Is Missing a NULL Value

this is my code:

//create private key
NSData* tag = [@"name" dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary* attributes =
@{ (id)kSecAttrKeyType: (id)kSecAttrKeyTypeRSA,
(id)kSecAttrKeySizeInBits: @2048,
(id)kSecPrivateKeyAttrs:
@{ (id)kSecAttrIsPermanent: @yES,
(id)kSecAttrApplicationTag: tag,
},
};

CFErrorRef error = NULL;
SecKeyRef privateKey = SecKeyCreateRandomKey((__bridge CFDictionaryRef)attributes,&error);
if (!privateKey) {
    NSError *err = CFBridgingRelease(error);  // ARC takes ownership
    // Handle the error. . .
}

//create public key
SecKeyRef publicKey = SecKeyCopyPublicKey(privateKey);
NSData *pubKey = (NSData *)CFBridgingRelease(SecKeyCopyExternalRepresentation(publicKey, &error));

CertificateSigningRequest *sccsr = [[CertificateSigningRequest alloc] init];
sccsr.commonName = @"CommonName";

NSData *certificateRequest = [sccsr build:pubKey privateKey:privateKey];
NSString *s = [certificateRequest base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];

NSString *strCertificateRequest = @"-----BEGIN CERTIFICATE REQUEST-----\n";
strCertificateRequest = [strCertificateRequest stringByAppendingString:s];
strCertificateRequest = [strCertificateRequest stringByAppendingString:@"\n-----END CERTIFICATE REQUEST-----\n"];
NSLog(@"%@" , strCertificateRequest);

return strCertificateRequest;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions