3

I am currently creating a Java program that uses the twitter4J.

I have a "consumer secret" from twitter that needs to be kept secret. However I am wanting to share the source and compiled jar with a few people.

Is there any way I can encrypt, or in some way hide the key in the source code/a local file so they can not access/view the key even when they have the source code?

CSmith
  • 90
  • 9

2 Answers2

3

Nope. If the Java compiler can read it, so can anyone else with the source code.

Michael Payne
  • 534
  • 5
  • 13
  • 1
    Share the key separately, on a separate file, a USB stick or whatever. As Michael says, anything in the source can be read. – rossum Apr 18 '16 at 18:43
  • OK Thanks. I guess I'll just have to exclude the secret and key from the source and ask them to register a new app with twitter and enter their own keys in the config file. – CSmith Apr 18 '16 at 18:44
2

If you are sharing the source, there really is no good way to accomplish this by just using source code.

If you were not sharing the source, you could follow the answer provided here: Best Practice for storing private API keys in Android

You could incorporate two-way encryption and store it in a separate file, which is detailed in this answer here: Encrypt Password in Configuration Files?

Community
  • 1
  • 1
Keenan
  • 179
  • 1
  • 9