Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JRE support for javax.crypto package #432

Closed
Ariesliuh opened this issue Nov 12, 2014 · 14 comments
Closed

Add JRE support for javax.crypto package #432

Ariesliuh opened this issue Nov 12, 2014 · 14 comments

Comments

@Ariesliuh
Copy link

Hi,
I used j2objc to convert java code to oc. I have convert the code by eclipse plugin. When I take the oc code to ios project, I have an error ActiveCodeHandler.java:10:10: 'javax/crypto/BadPaddingException.h' file not found. So I can not find the header in the dist/include. Now I have no idea for this. ps: The code isn't android project. Who can help me. thanks.

@tomball
Copy link
Collaborator

tomball commented Nov 12, 2014

While the JRE emulation support
https://github.com/google/j2objc/wiki/JRE-Emulation-Reference continues
to grow, j2objc can never be 100% JRE compatible. The translator should
have reported that this API isn't available as an error. Are you building
with --ignore-missing-imports? That flag is only useful when doing a first
pass over a large project, and shouldn't be used normally since all that
does is ignore an error that will show up when compiling the generated
files.

Please rebuild without this flag to get the full list of classes your Java
code needs, since exceptions are rarely the only classes used in a package.
My guess is that your code has other javax.crypto dependencies, and that
package isn't supported yet. I hope to work on security providers next, but
need to fix some serialization and reflection bugs first.

On Tue Nov 11 2014 at 11:52:57 PM Aries notifications@github.com wrote:

Hi,
I used j2objc to convert java code to oc. I have convert the code by
eclipse plugin. When I take the oc code to ios project, I have an error
ActiveCodeHandler.java:10:10: 'javax/crypto/BadPaddingException.h' file not
found. So I can not find the header in the dist/include. Now I have no idea
for this. ps: The code isn't android project. Who can help me. thanks.


Reply to this email directly or view it on GitHub
#432.

@Ariesliuh
Copy link
Author

Thanks your reply. There are some 'javax.crypto' dependencies in the java project.

@tomball tomball changed the title javax.crypto.NoSuchPaddingException Add JRE support for javax.crypto package Dec 23, 2014
@alexcrownus
Copy link

Hi,

Any idea when this might be done?

Thanks.

@lrbtony
Copy link

lrbtony commented Sep 25, 2015

Hi,

I have seen the latest code 0.9.8.1, and in it, there are already have the javax.crypto package show as below.
2015-09-25 3 41 52

But why I still can't import the javax.crypto package in my java code?
If there are solution to the question, please tell me how.

Thanks.

@tomball
Copy link
Collaborator

tomball commented Sep 25, 2015

You asked when it was done, and since there are 36 classes in javax.crypto,
it's not done. And 100% Java crypto support may never be done, as we only
plan on mapping what functionality has equivalents in the iOS Security
Framework. By basing our limited support on iOS security, any security
flaws will (hopefully) just be in the iOS platform itself and not our thin
security providers
https://github.com/google/j2objc/tree/master/jre_emul/Classes/com/google/j2objc/security
.

I strongly recommend that instead of waiting, you refactor your app's
encryption code into a utility class, then extract an interface from it to
encapsulate what your app needs from what the platform provides. Keep the
Java implementation of that interface for Android and any server-side code,
then implement an iOS version that maps directly to the Security Framework.
Most apps only need a small part of a big security API, so there shouldn't
be too much native code. Developers had a similar issue with SQLite
support, which has a large API but apps only needed a few calls and so were
easily implemented natively.

If your goal is to port an Android app while writing the minimum
iOS-specific code, another option you have is to use RoboVM. It has full
Java security support, though it does that through a BouncyCastle port plus
its own certificates. That means no integration with the iOS device, but
perhaps that's not a requirement for your app.

If you have some Java security skill, a third option is to implement the
missing security providers like the ones we've done, and contribute it to
our open-source project http://j2objc.org/docs/Contributing.html.

On Fri, Sep 25, 2015 at 12:46 AM lrbtony notifications@github.com wrote:

Hi,

I have seen the latest code 0.9.8.1, and in it, there are already have the
javax.crypto package show as below.
[image: 2015-09-25 3 41 52]
https://cloud.githubusercontent.com/assets/12557369/10095406/26c5118a-639c-11e5-89c0-8d8b76fedb43.png

But why I still can't import the javax.crypto package in my java code?
If there are solution to the question, please tell me how.

Thanks.


Reply to this email directly or view it on GitHub
#432 (comment).

@lrbtony
Copy link

lrbtony commented Sep 29, 2015

HI,
As I used your code to convert the java sourse code to objc , and then I got an object which the class is ComGoogleJ2objcSecurityIosRSAKey_IosRSAPrivateKey. But it wasn't the same to ObjC class SecKeyRef when I used it to decrypted my encryptedKey . It broke with out any informations that I could know why it didn't work. So I urgently want the javax.crypto.chiper that can help me to convert my encryptedKey into string.
Thank you all the same!

@tomball
Copy link
Collaborator

tomball commented Sep 29, 2015

@System25
Copy link

Why don't you use Bouncycastle library to improve javax.crypto support? Or at least provide the basic scaffolding to incoroporate Bouncycastle to a project?

Thanks

@tomball
Copy link
Collaborator

tomball commented Nov 10, 2017

Using crypto APIs other than the iOS Security Framework requires that every j2objc app would need to follow the U.S. Export Compliance steps, which may require submitting compliance declaration forms with every AppStore submission. You are of course welcome to directly include BouncyCastle in your own app if you are okay with this export requirement, but it can’t be included in the platform without impacting all other app teams using j2objc.

Before you translate BouncyCastle (not difficult, but it's big), consider what exactly your app's crypto requirements are. Java's security API is huge to handle all possible scenarios for all platforms, but most mobile apps have very narrow needs. These apps can therefore define a simple "security" or "crypto" interface for their cross-platform code, then implement it separately for Android and iOS, often with a single simple class since it just calls either the JRE on Android or the Security Framework on iOS. That's why we get requests for full JRE support when an app team first hits this issue, but then they don't need it later.

Unfortunately, every app's needs tend to be different, which is why we can't provide a security subset that will meet the needs of all j2objc users. We plan on implementing crypto next year, in large part because the macOS and iOS security APIs have been unifying in recent releases (especially iOS 10).

@tomball
Copy link
Collaborator

tomball commented Apr 26, 2021

The javax.crypto package was added to j2objc-2.0. We don't implement crypto support, due to the U.S. Export Compliance issues mentioned above.

@tomball tomball closed this as completed Apr 26, 2021
@thieren
Copy link

thieren commented Nov 2, 2022

Before you translate BouncyCastle (not difficult, but it's big)

Sorry for reopening this but I'd need help with exactly this: transpiling the bouncycastle source into a project.

I'd like to work with a java library that uses AES encryption (and some other) in its code and before I'd gone to the length of rewriting the code into objc native code, I thought about adding the appropriate security provider through bouncycastle to at least test if the code works after translating it to objc.

Unfortunately here I am a little lost: the first thing is that I don't really know which source from bouncycastle am I supposed to use. There are so many choices of different jdks and modules. Do I use only the prov module, or do I need to add the core also?
I know that this is not the bouncycastle repo here, so this question is most likely out of scope, but at least I DO find it difficult to transpire the bouncycastle source into objc.

In fact I have already tried various approaches. Using only the prov module and also with core, with different sources (jce, jcajce, ...) but every time there are compiling errors when trying to compile it with j2objc.
Mostly it is either missing classes (hence adding the core module) or there are class names doubled in different packages of the bouncycastle source.

I couldn't find anything that helps by searching other than the statement that it should be fairly simple (twice).

So any help would be appreciated (or a nudge in the right direction for that matter).

Thx!

@tomball
Copy link
Collaborator

tomball commented Nov 2, 2022 via email

@thieren
Copy link

thieren commented Nov 3, 2022

Thx for the nudge and the overall determination to help. :-)

The tip with finding a javac command first was very good. At least I got this to compile, so I think I've got the right source files now.

One major difference I've noticed between javac and j2objc command is, that when I compile a *.java (e.g. javac -d dist -sourcepath src ./src/org/path/to/my/file.java) it will compile all needed class files that my file.java depends on from other packages into the dist folder. But j2objc won't do the same for the objective-c code. Is there a way to get this working?

But that's actually no real problem in my case, since I've actually just looked at the generated *.class files and used the according *.java files in my Xcode project.
Unfortunately now I'm back at the error that says that multiple commands generate the same output file, since bouncycastle uses the same class names in different packages. If you've got any on that let me know.

Again, many thanks for your help!

@tomball
Copy link
Collaborator

tomball commented Nov 3, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants