gpt4 book ai didi

ios - 使用 objective-c 和 OpenSSL 创建 .PEM 文件

转载 作者:行者123 更新时间:2023-12-05 06:48:15 24 4
gpt4 key购买 nike

我正在尝试在 Objective-C 或 Swift 中实现以下命令行。

openssl x509 -req -in 20060.csr -CA root.pem -CAkey root.key -CAcreateserial -out 20060.pem -days 825 -sha256

我已经为我的 iOS 项目编译和构建了 openssl,并成功创建了带有一些 KeyChain 函数的 20060.csr 文件。我已经有了 root.pem 和 root.key 文件。

我如何在 Objc 中以编程方式实现这一点?

最佳答案

创建 PEM 文件 (CertificateSigningRequest.pem) 的代码。

- (void)createPemFileWithCertificateSigningRequest:(X509_REQ *)certSigningRequest {
//delete existing PEM file if there is one
[self deletePemFile];

//create empty PEM file
NSString *pemFilePath = [self pemFilePath];
if (![[NSFileManager defaultManager] createFileAtPath:pemFilePath contents:nil attributes:nil]) {
NSLog(@"Error creating file for PEM");
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error creating file for PEM" message:[NSString stringWithFormat:@"Could not create file at the following location:\n\n%@", pemFilePath] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
return;
}

//get a FILE struct for the PEM file
NSFileHandle *outputFileHandle = [NSFileHandle fileHandleForWritingAtPath:pemFilePath];
FILE *pemFile = fdopen([outputFileHandle fileDescriptor], "w");

//write the CSR to the PEM file
PEM_write_X509_REQ(pemFile, certSigningRequest);
//close the file
fclose(pemFile);
}

- (NSString *)pemFilePath {
NSString *documentsFolder = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
return [documentsFolder stringByAppendingPathComponent:@"CertificateSigningRequest.pem"];
}

关于ios - 使用 objective-c 和 OpenSSL 创建 .PEM 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66861914/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com