Last active
August 29, 2015 13:59
-
-
Save konstantinpavlikhin/10933246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ...import OpenSSL headers... | |
DSA* dsa = DSA_new(); | |
const char *privateKey = [[NSString stringWithContentsOfFile: @"/private.pem"] UTF8String]; | |
BIO* bio = BIO_new_mem_buf((void*)privateKey, -1); | |
PEM_read_bio_DSAPrivateKey(bio, &dsa, NULL, NULL); | |
BIO_vfree(bio); | |
// * * *. | |
NSData* digest = [[@"John Appleseed" dataUsingEncoding: NSUTF8StringEncoding] SHA1Data]; | |
unsigned char signature[100]; | |
unsigned int signatureLength; | |
if(!DSA_sign(NID_sha1, [digest bytes], [digest length], signature, &signatureLength, dsa)) | |
{ | |
NSLog(@"SIGNING FAILED"); | |
} | |
DSA_free(dsa); | |
NSString* serial = [[[NSData dataWithBytes: signature length: signatureLength] base32String] stringByReplacingOccurrencesOfString: @"=" withString: @""]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment