Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After several days of research finally i did it with OpenSSL. I'm not an expert in C++ so i'm not certainly sure if all chars, const chars and unsigned chars are declared correctly, so if anyone has a better idea please edit it =). You must have lybcrypto.a and libssl.a (here you can find them <a href="https://github.com/x2on/OpenSSL-for-iPhone" rel="nofollow">https://github.com/x2on/OpenSSL-for-iPhone</a>). I tested several times with EMV VISA keys and it works.</p> <pre><code>#include &lt;openssl/opensslv.h&gt; #include &lt;openssl/rsa.h&gt; #include &lt;openssl/evp.h&gt; #include &lt;openssl/bn.h&gt; @implementation ViewController -(NSData*) decryptIPKC:(NSString*)ipkc modulus:(NSString*)mod exponent:(NSString*)exp{ NSString * hexString = ipkc; int hexStringLength= [hexString length] / 2; //unsigned char enc_bin[144]; unsigned char dec_bin[hexStringLength]; //int enc_len; int dec_len; RSA * rsa_pub = RSA_new(); const char *N=[mod UTF8String] ; const char *E=[exp UTF8String]; char * myBuffer = (char *)malloc((int)[hexString length] / 2 + 1); bzero(myBuffer, [hexString length] / 2 + 1); for (int i = 0; i &lt; [hexString length] - 1; i += 2) { unsigned int anInt; NSString * hexCharStr = [hexString substringWithRange:NSMakeRange(i, 2)]; NSScanner * scanner = [[NSScanner alloc] initWithString:hexCharStr]; [scanner scanHexInt:&amp;anInt]; myBuffer[i / 2] = (char)anInt; } printf("Mybuffer: %s",myBuffer); if (!BN_hex2bn(&amp;rsa_pub-&gt;n, N)) { printf("NO CARGO EL MODULO"); } printf(" N: %s\n", N); printf(" n: %s\n", BN_bn2hex(rsa_pub-&gt;n)); if (!BN_hex2bn(&amp;rsa_pub-&gt;e, E)) { printf("NO CARGO EL EXPONENTE"); } printf(" E: %s\n", E); printf(" e: %s\n", BN_bn2hex(rsa_pub-&gt;e)); printf("public key size : %d bits\n", RSA_size(rsa_pub)); /* decrypt */ if ((dec_len = RSA_public_decrypt(hexStringLength, (unsigned char*)myBuffer, dec_bin, rsa_pub,RSA_NO_PADDING))&lt;0) { printf("NO\n "); } printf("decrypted data:\n %s", dec_bin); print_hex(dec_bin, dec_len); NSData* data = [NSData dataWithBytes:dec_bin length:sizeof(dec_bin)]; free(myBuffer); return data; } - (void)viewDidLoad { [super viewDidLoad]; NSString *m= @"Your HEX modulus here"; NSString *e=@"Your HEX exponent"; NSString * hexString= @"Your HEX message here"; NSData *decryptedIPKC= [self decryptIPKC:hexString modulus:m exponent:e]; NSLog(@"ESTE ES EL NSDATA %@", decryptedIPKC.description); } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload