1

I want to generate unique API Key and Secret Key and map each of this pair to unique projects in database. So I need a function to generate unique pair of keys.

How to generate unique api key and secret key in Java / database ?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Kenshin
  • 1,030
  • 2
  • 12
  • 41
  • have you tried Guid (in java that would be: UUID)? – mikus Nov 30 '15 at 09:03
  • 2
    what do you think when saying "secret key" ? What do you want to do with that ? (who owns the key, who can code, decode, etc.) ? – guillaume girod-vitouchkina Nov 30 '15 at 09:09
  • If you see ad network apis like Chartboost, Vungle, AdMob, etc. Once you create an application in their portal, you will be provided API Key and Secret Key. I want to replicate that feature – Kenshin Nov 30 '15 at 10:06
  • then you might be looking at sth like RSA, public + private keys pairs are rather well known and described encryption and authentication mechanism :) dependa what are you exactly up to. – mikus Nov 30 '15 at 11:23
  • I want to associate unique pair of key ( api key and secret ) to every project in my database. Using that, every client can authenticate REST url using public/private key authentication... – Kenshin Nov 30 '15 at 13:38

1 Answers1

1

I didnt study functionalities of Charboost, it's not the initial question.

I only get that you would get some secret/public Key (this site use signature for example), then an asymetric pair of key. After, you do what your want.

For this rather general purpose, I propose to use RSA, well implemented in Java (other algorithms exist).

see this post: Generate RSA key pair and encode private as string

public key =>

KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(512);
    byte[] publicKey = keyGen.genKeyPair().getPublic().getEncoded();

private key =>

byte[] privateKey = keyGen.generateKeyPair().getPrivate().getEncoded();
Community
  • 1
  • 1