我正在尝试在不使用 openSSL 的情况下在 iOS am OSX 中以编程方式创建证书请求(我将发送到服务器)。我已经设法创建了 RSA key 对,但我无法完成其余的工作。我的代码完全符合我的需要,但它是用 Java 编写的,我想知道是否有人可以帮助我将其转换为 objective-c 。
Java代码如下:
test.generateKeys(); // generate RSA key pair
PrivateKey privateKey = test.keys.getPrivate();
PublicKey publicKey = test.keys.getPublic();
SecureRandom sr = new SecureRandom();
String token = "123456"; // dummy token
String uuid = "4670ff33-d9f7-4026-957d-25c00e4dec54"; // dummy uuid
// with Bouncy Castle
ContentSigner signGen = new JcaContentSignerBuilder("SHA1withRSA").setSecureRandom(sr).build(privateKey);
X500Principal subject = new X500Principal("O=" + token + ", CN=" + uuid);
PKCS10CertificationRequestBuilder builder = new JcaPKCS10CertificationRequestBuilder(subject, publicKey);
PKCS10CertificationRequest request = builder.build(signGen);
String bc = Hex.encodeHexString(request.getEncoded());
System.out.println(PEMtoString(request));
我不是很擅长密码学,而且苹果正在开发的加密层的文档记录很差,所以我在这里有点迷路。我遇到过很多类似的样本,但总有一些缺失。 提前致谢。
最佳答案
如果有人遇到同样的问题,这里是使用 Apple 通用加密层(无 openSSL)的解决方案。
https://github.com/ateska/ios-csr
只需一个简单的包含,无需花费数周的时间编写代码。
SCCSR *sccsr = [[SCCSR alloc] init];
sccsr.commonName = @"some name";
sccsr.organizationName = @"some organisation";
// // aditional data you can set
// sccsr.countryName = @"";
// sccsr.organizationalUnitName = @"";
// sccsr.subjectDER = nil;
// //
//
NSData *certificateRequest = [sccsr build:pPublicKey privateKey:privateKey];
NSString *str = [certificateRequest base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSString *strCertificateRequest = @"-----BEGIN CERTIFICATE REQUEST-----\n";
strCertificateRequest = [strCertificateRequest stringByAppendingString:str];
strCertificateRequest = [strCertificateRequest stringByAppendingString:@"\n-----END CERTIFICATE REQUEST-----\n"];
SCCSR.h -> 从提供的链接下载
关于java - ios 以编程方式创建证书请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26287514/