1、openssl生成的public_key.der文件导入到Xcode项目中,读取证书时候一直报路径为空,NSString *path = [[NSBundle mainBundle] pathForResource:@"public_key" ofType:@"der"]; 断点看到这个path一直为nil,
2、java后台服务器给我传了个rsa公钥对象,里面有modulus、exponent等字段,我怎么用这个公钥对象生成iOS中的公钥进行加密
2、java后台服务器给我传了个rsa公钥对象,里面有modulus、exponent等字段,我怎么用这个公钥对象生成iOS中的公钥进行加密
解决方案 »
- ios socket与javasocket通信问题
- ios 静态库crash问题
- @synthesize hello = _hello; 还不很理解。
- 给定一张图片 不利用图形上下文 直接生成自定义尺寸的图片 这个要怎么写呢
- oc中怎么调cpp文件里面的方法
- 我开发的OSX mac应用能在xcode里面运行却无法在外部运行。求解。
- 如何通过自定义CollectionViewlayout,向界面中添加补充视图SupplementaryView?
- UITabBarController中未选中图标的颜色问题
- ios开发收回键盘使用了第三方的IQKeyboardManager 有时候会出现黑屏???怎么搞啊?求大神啊
- 急!急! iOS 上传的APP的时候,报错包内的Info.plist中没有CFBundleVersion,这个怎么解决
- iOS程序跳转界面假死
- 关于UIButton使用setAttributedTitle:forState:之后无法改变标题颜色
//公钥加密
+(NSString *)RSAEncrypotoTheData:(NSString *)plainText publicKey:(NSString *) key;.m文件
+(NSString *)RSAEncrypotoTheData:(NSString *)plainText publicKey:(NSString *) key
{
SecKeyRef publicKey=[self addPublicKey:key];
size_t cipherBufferSize = SecKeyGetBlockSize(publicKey);
uint8_t *cipherBuffer = NULL;
cipherBuffer = malloc(cipherBufferSize * sizeof(uint8_t));
memset((void *)cipherBuffer, 0*0, cipherBufferSize);
NSData *plainTextBytes = [plainText dataUsingEncoding:NSUTF8StringEncoding];
size_t blockSize = cipherBufferSize-11; // 这个地方比较重要是加密问组长度
int numBlock = (int)ceil([plainTextBytes length] / (double)blockSize);
NSMutableData *encryptedData = [[NSMutableData alloc] init];
for (int i=0; i<numBlock; i++) {
long bufferSize = MIN(blockSize,[plainTextBytes length]-i*blockSize);
NSData *buffer = [plainTextBytes subdataWithRange:NSMakeRange(i * blockSize, bufferSize)];
OSStatus status = SecKeyEncrypt(publicKey,
kSecPaddingPKCS1,
(const uint8_t *)[buffer bytes],
[buffer length],
cipherBuffer,
&cipherBufferSize);
if (status == noErr)
{
NSData *encryptedBytes = [[NSData alloc]
initWithBytes:(const void *)cipherBuffer
length:cipherBufferSize];
[encryptedData appendData:encryptedBytes];
}
else
{
return nil;
}
}
if (cipherBuffer)
{
free(cipherBuffer);
}
NSString *encrypotoResult=[NSString stringWithFormat:@"%@",[encryptedData base64EncodedStringWithOptions:0]];
return encrypotoResult;
}