gpt4 book ai didi

macos - 相当于 Mac OS X 上的 SecKeyRawVerify 的功能?

转载 作者:行者123 更新时间:2023-12-04 21:08:03 24 4
gpt4 key购买 nike

我正在尝试为 MacOSX (>10.6) 创建一个与 iOS SecKeyRawVerify(验证数字签名)功能相同的功能,但到目前为止我无法这样做。我想知道为什么 Apple 会为 iOS 提供这样的功能而没有另一个为 OSX 做同样的工作?

非常感谢任何帮助,我整天都在为此苦苦挣扎。

iOS 功能简述:

SecKeyRawVerify

Verifies a digital signature.

OSStatus SecKeyRawVerify (
SecKeyRef key,
SecPadding padding,
const uint8_t *signedData,
size_t signedDataLen,
const uint8_t *sig,
size_t sigLen
);

Parameters

key
Public key with which to verify the data.

padding
The type of padding used. Possible values are listed in “Digital Signature Padding Types.” Use kSecPaddingPKCS1SHA1 if you are verifying a PKCS1-style signature with DER encoding of the digest type and the signed data is a SHA1 digest of the actual data. Specify kSecPaddingNone if no padding was used.

signedData
The data for which the signature is being verified. Typically, a digest of the actual data is signed.

signedDataLen
Length in bytes of the data in the signedData buffer.

sig The digital signature to be verified.

sigLen Length of the data in the sig buffer.

Return Value A result code. See “Certificate, Key, and Trust Services Result Codes.”

Availability
Available in iOS 2.0 and later.

最佳答案

在 OS X 上你必须使用安全转换,比如:

CFErrorRef error;
SecTransformRef verifier = SecVerifyTransformCreate(publicKey,
(CFDataRef)signature,
&error);
if (error) { CFShow(error); exit(-1); }

SecTransformSetAttribute(verifier,
kSecPaddingKey,
kSecPaddingPKCS1Key,
&error);
if (error) { CFShow(error); exit(-1); }


/* Specify digest type */
SecTransformSetAttribute(verifier,
kSecDigestTypeAttribute,
kSecDigestSHA1,
&error);
if (error) { CFShow(error); exit(-1); }

/* Raw data */
SecTransformSetAttribute(verifier,
kSecTransformInputAttributeName,
dataWithoutSignature,
&error);

CFTypeRef result = SecTransformExecute(verifier, &error);
if (error) {
CFShow(error);
exit(-1);
}

if (result == kCFBooleanTrue)
{
NSLog(@"VERIFY: success.");
}
else
{
NSLog(@"VERIFY: failure, again...");
}

关于macos - 相当于 Mac OS X 上的 SecKeyRawVerify 的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22004827/

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