ios-csr
ios-csr copied to clipboard
signature not valid
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;
@zealit you can use this library, it works on both RSA and EC https://github.com/aleemrazzaq/iOSCSR
this is also for iOS, not for OS X unfortunately. Is it possible to adapt your library so it's useful on OS X?
Any updates on this one? facing the same issue