Java ios以编程方式创建证书请求
我正在尝试在iOS am OSX中以编程方式创建证书请求(我将发送到服务器),而不使用openSSL。我已经成功地创建了RSA密钥对,但其余的都失败了。我有完全符合我需要的代码,但它是用Java编写的,我想知道是否有人能帮我将其翻译成objective c 以下是Java代码:Java ios以编程方式创建证书请求,java,ios,objective-c,cryptography,public-key-encryption,Java,Ios,Objective C,Cryptography,Public Key Encryption,我正在尝试在iOS am OSX中以编程方式创建证书请求(我将发送到服务器),而不使用openSSL。我已经成功地创建了RSA密钥对,但其余的都失败了。我有完全符合我需要的代码,但它是用Java编写的,我想知道是否有人能帮我将其翻译成objective c 以下是Java代码: test.generateKeys(); // generate RSA key pair PrivateKey privateKey = test.keys.getPrivate();
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));
我对密码学不是很在行,而且苹果正在开发的加密层的文档也很差,所以我在这里有点迷茫。我遇到过很多类似的样品,但总是缺少一些东西。
Thx提前。如果有人遇到同样的问题,这里是使用苹果通用加密层(无openSSL)的解决方案 不需要几个星期的编码,只需要一个简单的include
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->从提供的链接下载强烈建议您使用openssl。如果没有,准备好几周的努力。看,我会使用openSSl,但据我所知,苹果公司正在劝阻其开发人员在他们正在开发的新加密层上使用openSSl,所以我不想编写将来或smth会被拒绝的程序。像这样,如何为服务器有效性创建证书?