在尝试从Apple的示例实现Security.Framework SecKeyRawVerify iOS函数时,程序停止时出现错误的指针错误(EXC_BAD_ACCESS代码= 2).任何帮助或建议将不胜感激.
这是我的代码:
- (BOOL)verifySignature:(NSData *)plainText signature:(NSData *)sig {
size_t signedHashBytesSize = 0;
OSStatus sanityCheck = noErr;
SecKeyRef publicKeyA = NULL;
NSMutableDictionary * queryPublicKeyA = [[NSMutableDictionary alloc] init];
NSData * publicTag = [NSData dataWithBytes:publicKeyAIdentifier length:strlen((const char *)publicKeyAIdentifier)]; //
// Set the public key query dictionary.
[queryPublicKeyA setObject:(id)kSecClassKey forKey:(id)kSecClass];
[queryPublicKeyA setObject:publicTag forKey:(id)kSecAttrApplicationTag];
[queryPublicKeyA setObject:(id)kSecAttrKeyTypeRSA forKey:(id)kSecAttrKeyType];
[queryPublicKeyA setObject:[NSNumber numberWithBool:YES] forKey:(id)kSecReturnData];
// Get the key bits.
sanityCheck = SecItemCopyMatching((CFDictionaryRef)queryPublicKeyA, (CFTypeRef *)&publicKeyA);
if (sanityCheck == noErr) {
// Get the size of …
Run Code Online (Sandbox Code Playgroud) 我有一些代码用于加密和解密ios应用程序中的某些字符串.该代码涉及CCCrypt的使用.有没有一种可靠的方法来测试所使用的密钥的有效性而无需将密钥实际存储在任何地方?根据我的研究,似乎接近告知密钥是否有效的唯一方法是使用密钥长度和密钥哈希.任何人都可以指导我正确的方向吗?
我试图解码从服务器返回的PHP中的数据:我知道数据AES 256解码并具有PKCS7填充,但无法弄清楚它使用哪种块模式
这是我的PHP功能:
public function decode($data)
{
//AES decode
$iv = mcrypt_create_iv(GEServerConnection::FBENCRYPT_BLOCK_SIZE, MCRYPT_RAND);
$data = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->cryptKey, base64_decode($data), MCRYPT_MODE_ECB, $iv);
//return $data;
$len = strlen($data);
$pad = ord($data[$len - 1]);
return substr($data, 0, - $pad);
}
Run Code Online (Sandbox Code Playgroud)
和编码数据的例子
3KD+zb/2u5gGEWvOy0Q0nSQE9pbQZmg27iN6WLiO/Af9YjN8MhHOb8TMa5uETaab
Run Code Online (Sandbox Code Playgroud)
当我使用ECB(MCRYPT_MODE_ECB)进行解码时,它只解码数据的开头并且其余部分无法读取
"Please input yo??????g|??*P?Te??? R?B
Run Code Online (Sandbox Code Playgroud)
当用CBC(MCRYPT_MODE_CBC)模式解码时,它开始不可读
??0?=v??????.3ur username and password again"
Run Code Online (Sandbox Code Playgroud)
结果应该是(在Objective-c中使用CommonCryptor获得的mac):
"Please input your username and password again"
Run Code Online (Sandbox Code Playgroud)
有人知道什么是错的或如何以正确的方式解码它?
我发现我们可以用 CommonCrypto 哈希一些字符串。我看到了一些例子,但他们不使用盐。如何将 SHA256 与盐一起使用?
我有导入CommonCrypto/CommonCrypto
或问题CommonCrypto/CommonDigest
.我的Swift
代码需要一个SHA256 .
我CommonCrypto
在Cocoapods 找到了github网站.
https://github.com/AlanQuatermain/aqtoolkit
所以我从上面下载了文件.但是我遇到了错误ARC
(我像其他教程一样添加了Bridging-Header.)
头文件的名称是NSData+CommonCrypto.h
和NSData+CommonCrypto.m
.
这不是一个CommonCrypto/CommonCrypto
或CommonCrypto/CommonDigest
哪里可以下载并获取CommonCrypto
SHA256 的确切文件?
我正在尝试使用iPhone的PKI库来加密短字符串(12345678),但每当我尝试使用SecKeyEncrypt时,我都会收到错误-9809(即errSSLCrypto).SecureTransport.h头文件将此错误描述为"底层加密错误",这不是很有意义.
我的代码如下:
- (NSData *)encryptDataWithPublicKey:(NSString *)plainText {
OSStatus result = -1;
NSData *plainTextData = [plainText dataUsingEncoding:NSASCIIStringEncoding];
size_t plainTextLength = [plainTextData length];
SecTrustRef trustRef;
SecTrustResultType trustResult;
SecPolicyRef policy = SecPolicyCreateBasicX509();
result = SecTrustCreateWithCertificates(m_oCert, policy, &trustRef);
if (result != errSecSuccess) {
NSLog(@"Trust create failed with code: %d",result);
return nil;
}
result = SecTrustEvaluate(trustRef, &trustResult);
if (result != errSecSuccess) {
NSLog(@"Trust eval failed with code: %d",result);
CFRelease(trustRef);
return nil;
}
SecKeyRef publicKey = SecTrustCopyPublicKey(trustRef);
uint8_t *cipherTextBuf = NULL;
size_t cipherTextLen = 0;
size_t …
Run Code Online (Sandbox Code Playgroud) iphone pki public-key-encryption x509certificate commoncrypto
我在Mac OS 10.7上使用CommonCrypto进行加密.这个框架不是内置的吗?当我生成随机数据时:
+ (NSData *)randomDataOfLength:(size_t)length {
NSMutableData *data = [NSMutableData dataWithLength:length];
int result = SecRandomCopyBytes(kSecRandomDefault,
length,
data.mutableBytes);
NSAssert(result == 0, @"Unable to generate random bytes: %d",
errno);
return data;
}
Run Code Online (Sandbox Code Playgroud)
我得到错误使用未声明的标识符kSecRandomDefault,我相信它是在CommonCrypto中声明的.
谢谢,非常感谢所有帮助.
如何将Obj-C CommonCrypto库导入现有的Swift Xcode项目(Swift 3,Xcode 8.3.3)?
我试图创建自己的Objective-C桥接文件,但它无法正常工作.
我想用 iv 和 key 实现 AES128 CTR。我正在寻找如何以最好的方式做到这一点而不是重新发明轮子的建议。
我找到了这个RNCryptor的好库,但看起来那里不支持这个 aes。
我也测试了这种方法,但看起来这不是点击率。
编辑
我使用了 @zaph 的 zpproach
NSData *result = [NSData cryptData:dataStr
operation:kCCEncrypt
mode:kCCModeCTR
algorithm:kCCAlgorithmAES128
padding:ccNoPadding
keyLength:kCCKeySizeAES128
iv:ivHex
key:keyHex
error:&error];
Run Code Online (Sandbox Code Playgroud)
但收到CCCryptorCreate status: -4305
刚刚在源码中找到的
@constant kCCUnimplemented Function not implemented for the current algorithm.
commoncrypto ×10
ios ×6
aes ×4
objective-c ×4
encryption ×3
swift ×3
cocoa ×1
cryptography ×1
iphone ×1
mcrypt ×1
php ×1
pki ×1
public-key ×1
sha256 ×1