Skip to content

Commit

Permalink
verifySignatureWithSHA512 implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
“bill.chan” committed Apr 13, 2015
1 parent 89590ee commit 53c6ec5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions MIHCrypto/Core/MIHPublicKey.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@
*/
- (BOOL)verifySignatureWithSHA256:(NSData *)signature message:(NSData *)message;

- (BOOL)verifySignatureWithSHA512:(NSData *)signature message:(NSData *)message;

@end
21 changes: 20 additions & 1 deletion MIHCrypto/RSA/MIHRSAPublicKey.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,32 @@ - (BOOL)verifySignatureWithSHA256:(NSData *)signature message:(NSData *)message
return YES;
}

- (BOOL)verifySignatureWithSHA512:(NSData *)signature message:(NSData *)message
{
SHA512_CTX sha512Ctx;
unsigned char messageDigest[SHA512_DIGEST_LENGTH];
if(!SHA512_Init(&sha512Ctx)) {
return NO;
}
if (!SHA512_Update(&sha512Ctx, message.bytes, message.length)) {
return NO;
}
if (!SHA512_Final(messageDigest, &sha512Ctx)) {
return NO;
}
if (RSA_verify(NID_sha512, messageDigest, SHA512_DIGEST_LENGTH, signature.bytes, (int)signature.length, _rsa) == 0) {
return NO;
}
return YES;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark NSObject
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

- (NSString *)description
{
return [[self dataValue] MIH_base64EncodedString];
return [[NSString alloc] initWithData:[self dataValue] encoding:NSUTF8StringEncoding];
}

@end

1 comment on commit 53c6ec5

@hohl
Copy link

@hohl hohl commented on 53c6ec5 Feb 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, would you like to push that to the main repo? (Would just require some unit tests, but they would be just some copy & paste from SHA256.)

Please sign in to comment.