View the workflow
🏋️♀️ Product Releases
|
🤹♀️ Recent Blog
|
Example for RSA encryption & decryption on iOS
License: MIT License
View the workflow
🏋️♀️ Product Releases
|
🤹♀️ Recent Blog
|
NSString *password=@"123456";
[JSRSA sharedInstance].publicKey=@"public_key.pem";
[JSRSA sharedInstance].privateKey=@"private_key.pem";
NSString *upass=[[JSRSA sharedInstance] publicEncrypt:password];
hi,when i use this util ,sometimes encrypt text return nil
Change extention .c to .m otherwise XCode6 compile error
Hello Lim
Your project is helpful. And I think its necessary to add a flag to contol the console print show or hide . Should I do this and pull requests for your project ?
When completing the import, I cannot compile the project. I get:
Undefined symbols for architecture x86_64:
"OBJC_CLASS$_JSRSA", referenced from:
type metadata accessor for ObjectiveC.JSRSA in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
With a 512 bit public key, public key encryption (using js_public_encrypt
function) fails occasionally. It doesn't print any error messages in case of a failure and just returns a broken string. When using a 2048 bit public key, the failure rate increases significantly (almost every time, but my data set (some JSON strings) might not be representative.). However when it fails to encrypt, a second or third re-attempt with the same configuration usually works. Very strange.
For some string when i am running in iPhone, i get encrypted string as follows
PWzAkKHRhbitHz7L0fn4teVED6xbd8xUmJpwi8qC+eJPGI0JYJD2zCbz+vHj3pF8jSS24Avw0BnlPF65QUtuzzUy7gw1FO2ICoSUTfiZ13Dy6lavVZJE7kiw7eByyxRhesYpFZIHSgn+CMObns9wyi5G5LovhJyf+XDCnvd1g1ChkRcKRVPspPm7Bc3R2B+Gkz/S2QVvSgUwphuyl5lRGQtgvkxItOY2QrNmjbSudoeTfH5TnNl+gq8cqygr6tSQnRUJiZF+/MC3+H0PBldtmkVgdB2fnlp083UCfUbmJgRnE84pUq9IpHmD2C3BxP1KNnNTA86xVB/m4WFEx7WoBph1KkYtjsTaLtFLIrX6P1HfC23n9YHWxELRewTFUsh9PxphN8BtFO4q0VaQRLw4zvLJlTKS8GP+37BsX4ZSgf1h1S3E8u5AlVfJPEbUgukyCn4K3MEvGqQ9R236ptBO1rO/sM5tqB4DYE86oQbNWqx4zTcYdS8j2kKCLX4gyUzrFIO03GNARpYuJKHJbDrK0PiREuPM/a024M9WbbnTnJZdwrBWeGaWajUyY8aUPdpcsz6VOjjWNxpb8GfMRxPr8hrLnayrGSYNWrEpLJHY6fZMBS+FVq2KSJJoPlDDtdkMK+I++JYqnMIH3apMuy543yreadwiYz5WFuzK+D2BUq40UBhOA6mYtShFQRwRS48O7rh2jaPNmjSj8SnlNmpcnucomWsUTtqslMfrKeOCYsBh5VShxWQwEWICWF9FQ8EDGbpWYJz9q/6yWe5+7IWrnMkKKRa3JVAszrE+R3MzIamoomw3Yns7OabGECMfKkODcvht3Sr195RUIKsvnk06qQJZc93pcTBLWk5otA7BN03rUwcTZfmCjy3Q98PPjWwL3Y2Vlu+pyJ/4+EROnGVNPYBnESO73lLShAc3kA+VCmvapilSbAIlAGdjlJHnpwR+GMIOPkpAKhUDjJhUOTEH+ijSNFNuyyYb/gp+hrJU3JOm08fTBIQdNvWITWmX/rQPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
This is creating issues while decrypting last chunk. It is throwing bad access.
Hi all,
I am working on a project in which i need to encrypt and decrypt the data using private and public keys but these both keys are came from server but in example it take keys from pem files, if there is any way to encrypt the data using own Private and Public keys kindly guide me.
Thanks in advance.
Hi, back with another issue, base64 encoding sometimes gives invalid output, for example: FsYAyq8KfCz5B41dRDqxuZR8xhvFuAKZE7nWDn3MrnCRYio8wj0PYeNDD1u4G/Bj36fjPWMUzx+CZfSjZhOaHMBC7cnbw0D5JrN2RDLFHQC5C7Mkw7I1Oq2mf5byDl+ayHHAGHqv8Ztj4zBuBJX4v1ZF48BGW+mNiiQWtiFBVODbL6Qu56Do1iyaoRaStRKwtd9mppdmmZJWa8YTtt7+9Q1yB07IRan+Qg5kUku8AmRLp9nNZ3k1/60pv+V7nPp7CkYWIZ3ASNQOVMRbsjoiEfmPlipuZtLLVqJTLY8xGaFuKSvQ5Ibdj0GUkycWbZYbe8T4KaFyk55qlapyUsFArw==ar=grego
The characters after == shouldn't be there, but there is data stored in them since it also doesn't work if I remove them.
Any fixes/workarounds available? My C skills are terrible so I'm at a loss here. Different encoding (hex for example) would also be ok.
Other example: Pi/+a+8kPNZRZk4Mm+vjniOmUMzE67/69P7/vP/pySJ4QFWWpVSSSEQuX+LB+vCF85neGbJ2fp4DYuZFI0eZyo382zCThxEAjmATUAXmAz4ZgopQkQVv9MHPTVzbRecDcY1t+AeiyhhHhXzNl4U2e0xYrEgnZcrZXE8/YfmoPgr2yeBNfIRQE2BFLXNZRGZUZkdzbjrhmouBclgv7mN37SPZr0gj8VSSbKzOM5ElGKuw4joc9iIJhG5x99Z617STNkbXg5KgHbFLs9/rrafd6obHkiLltmFqsaw/MNgkpm7YrIKaa2XxlUkiNE5EOp37A7snsKlJpa3HBGDPom+D1Q==µ∫Âfl›öQ'
Usage:
JSRSA.sharedInstance().privateKey = "private_key.pem"
let str = String(NSDate().timeIntervalSince1970 * 1000)
let stamp = str[str.startIndex.advancedBy(0)...str.startIndex.advancedBy(9)]
let encrypt = JSRSA.sharedInstance().privateEncrypt(stamp)
return encrypt.base64Encoded()
Every now and then (40% of the time) I get the following error:
RSA private length: 128
Plain chunk: 1450115145_�
Encrypted Result chunk: I4j\323N\270~j\332\313\301=\214ݓ\345՟\266숤M\230\365Ô\347D\370V^u\227i #$Uģ\334\303\363\221LS\377'�\365@\212>\377ٗ6)'\376\352_d\333\372
\257\243 S�\364!\274Kmعt\354�\350\221\342 \275�@\315K�&D
\237\274ɡDO�=�\254\237L-_*}\314D\336
Encrypted Chunk length: 128
Total cipher length: 128
Final result: STRq0064fmray8E9jN2T5dWftuyIpE2Y9cOU50T4Vl51l2kJIyRVxKPcw/ORTFP/Jx71QIo+/9mXNikn/uoqZNv6Da+jIFMX9CG8S23YuXTsG+iR4gy9H0DNSxsmRA2fvMmhRE8RPRysn0wtKip9zETeAJSbx+h6Hk/rSC2vWt0=\201Q\301�
Final result length: 172
fatal error: unexpectedly found nil while unwrapping an Optional value
And it breaks here:
libswiftCore.dylib`function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ():
0x100350740 <+0>: stp x29, x30, [sp, #-16]!
0x100350744 <+4>: mov x29, sp
0x100350748 <+8>: sub sp, sp, #16
0x10035074c <+12>: and w8, w2, #0x1
0x100350750 <+16>: tbnz w8, #0, 0x100350770 ; <+48>
0x100350754 <+20>: tbnz x1, #63, 0x1003507b4 ; <+116>
0x100350758 <+24>: add x1, x0, x1
0x10035075c <+28>: mov x2, x3
0x100350760 <+32>: mov x3, x4
0x100350764 <+36>: mov x4, x5
0x100350768 <+40>: bl 0x100392dd0 ; function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded> of Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()).(closure #2)
-> 0x10035076c <+44>: brk #0x1
0x100350770 <+48>: str xzr, [sp, #8]
0x100350774 <+52>: cmp x0, w0, uxtw
0x100350778 <+56>: b.ne 0x10035094c ; <+524>
0x10035077c <+60>: lsr w8, w0, #11
0x100350780 <+64>: cmp w8, #26
0x100350784 <+68>: b.hi 0x1003507d8 ; <+152>
0x100350788 <+72>: cmp w0, #128
0x10035078c <+76>: b.lo 0x100350808 ; <+200>
0x100350790 <+80>: orr w8, wzr, #0x80
0x100350794 <+84>: bfxil x8, x0, #0, #6
0x100350798 <+88>: cmp w0, #2048
0x10035079c <+92>: b.hs 0x10035083c ; <+252>
0x1003507a0 <+96>: movz x10, #0
0x1003507a4 <+100>: movz x11, #0
0x1003507a8 <+104>: lsr w9, w0, #6
0x1003507ac <+108>: orr w9, w9, #0xffffffc0
0x1003507b0 <+112>: b 0x10035086c ; <+300>
0x1003507b4 <+116>: adr x0, #808224 ; "fatal error"
0x1003507b8 <+120>: nop
0x1003507bc <+124>: adr x3, #808724 ; "UnsafeBufferPointer with negative count"
0x1003507c0 <+128>: nop
0x1003507c4 <+132>: movz w1, #0xb
0x1003507c8 <+136>: orr w2, wzr, #0x2
0x1003507cc <+140>: movz w4, #0x27
0x1003507d0 <+144>: orr w5, wzr, #0x2
0x1003507d4 <+148>: bl 0x100350740 ; <+0>
0x1003507d8 <+152>: cmp w0, #14, lsl #12
0x1003507dc <+156>: b.lo 0x100350818 ; <+216>
0x1003507e0 <+160>: cmp w0, #272, lsl #12
0x1003507e4 <+164>: b.hs 0x100350900 ; <+448>
0x1003507e8 <+168>: orr w8, wzr, #0x80
0x1003507ec <+172>: bfxil x8, x0, #0, #6
0x1003507f0 <+176>: orr w9, wzr, #0xffffff80
0x1003507f4 <+180>: bfxil w9, w0, #6, #6
0x1003507f8 <+184>: lsr w10, w0, #16
0x1003507fc <+188>: cbnz w10, 0x100350924 ; <+484>
0x100350800 <+192>: lsr w10, w0, #12
0x100350804 <+196>: b 0x100350848 ; <+264>
0x100350808 <+200>: movz x9, #0
0x10035080c <+204>: movz x11, #0
0x100350810 <+208>: mov x8, x0
0x100350814 <+212>: b 0x10035089c ; <+348>
0x100350818 <+216>: adr x0, #808124 ; "fatal error"
0x10035081c <+220>: nop
0x100350820 <+224>: adr x3, #811328 ; "high- and low-surrogate code points are not valid Unicode scalar values"
0x100350824 <+228>: nop
0x100350828 <+232>: movz w1, #0xb
0x10035082c <+236>: orr w2, wzr, #0x2
0x100350830 <+240>: movz w4, #0x47
0x100350834 <+244>: orr w5, wzr, #0x2
0x100350838 <+248>: bl 0x100350740 ; <+0>
0x10035083c <+252>: lsr w10, w0, #12
0x100350840 <+256>: orr w9, wzr, #0xffffff80
0x100350844 <+260>: bfxil w9, w0, #6, #6
0x100350848 <+264>: movz x12, #0
0x10035084c <+268>: movz x11, #0
0x100350850 <+272>: orr w10, w10, #0xffffffe0
0x100350854 <+276>: and x10, x10, #0xff
0x100350858 <+280>: lsl x13, x12, #3
0x10035085c <+284>: lsl x10, x10, x13
0x100350860 <+288>: orr x11, x10, x11
0x100350864 <+292>: str x11, [sp, #8]
0x100350868 <+296>: add x10, x12, #1
0x10035086c <+300>: orr w12, wzr, #0x8
0x100350870 <+304>: umulh x12, x10, x12
0x100350874 <+308>: cmp xzr, x12
0x100350878 <+312>: b.ne 0x10035094c ; <+524>
0x10035087c <+316>: lsl x12, x10, #3
0x100350880 <+320>: cmp x12, #63
0x100350884 <+324>: b.hi 0x1003508dc ; <+412>
0x100350888 <+328>: and x9, x9, #0xff
0x10035088c <+332>: lsl x9, x9, x12
0x100350890 <+336>: orr x11, x9, x11
0x100350894 <+340>: str x11, [sp, #8]
0x100350898 <+344>: add x9, x10, #1
0x10035089c <+348>: orr w10, wzr, #0x8
0x1003508a0 <+352>: umulh x10, x9, x10
0x1003508a4 <+356>: cmp xzr, x10
0x1003508a8 <+360>: b.ne 0x10035094c ; <+524>
0x1003508ac <+364>: lsl x10, x9, #3
0x1003508b0 <+368>: cmp x10, #64
0x1003508b4 <+372>: b.hs 0x1003508dc ; <+412>
0x1003508b8 <+376>: and x8, x8, #0xff
0x1003508bc <+380>: lsl x8, x8, x10
0x1003508c0 <+384>: orr x8, x8, x11
0x1003508c4 <+388>: str x8, [sp, #8]
0x1003508c8 <+392>: add x8, sp, #8
0x1003508cc <+396>: add x8, x9, x8
0x1003508d0 <+400>: add x1, x8, #1
0x1003508d4 <+404>: add x0, sp, #8
0x1003508d8 <+408>: b 0x10035075c ; <+28>
0x1003508dc <+412>: adr x0, #807928 ; "fatal error"
0x1003508e0 <+416>: nop
0x1003508e4 <+420>: adr x3, #808332 ; "shift amount is larger than type size in bits"
0x1003508e8 <+424>: nop
0x1003508ec <+428>: movz w1, #0xb
0x1003508f0 <+432>: orr w2, wzr, #0x2
0x1003508f4 <+436>: movz w4, #0x2d
0x1003508f8 <+440>: orr w5, wzr, #0x2
0x1003508fc <+444>: bl 0x100350740 ; <+0>
0x100350900 <+448>: adr x0, #807892 ; "fatal error"
0x100350904 <+452>: nop
0x100350908 <+456>: adr x3, #811176 ; "value is outside of Unicode codespace"
0x10035090c <+460>: nop
0x100350910 <+464>: movz w1, #0xb
0x100350914 <+468>: orr w2, wzr, #0x2
0x100350918 <+472>: movz w4, #0x25
0x10035091c <+476>: orr w5, wzr, #0x2
0x100350920 <+480>: bl 0x100350740 ; <+0>
0x100350924 <+484>: lsr w10, w0, #18
0x100350928 <+488>: orr w11, w10, #0xf0
0x10035092c <+492>: cmp w11, w11, uxtb
0x100350930 <+496>: b.ne 0x10035094c ; <+524>
0x100350934 <+500>: orr w10, wzr, #0xffffff80
0x100350938 <+504>: bfxil w10, w0, #12, #6
0x10035093c <+508>: and x11, x11, #0xff
0x100350940 <+512>: str x11, [sp, #8]
0x100350944 <+516>: orr w12, wzr, #0x1
0x100350948 <+520>: b 0x100350854 ; <+276>
0x10035094c <+524>: brk #0x1
Every time, there is other words in the end of decrypt text. But iOS native is OK. @jslim89
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.