Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generating Nonce value for Orkut Oauth

 
kalpesh pradhan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone please help me with the following issue..

I am creating an web based application for orkut. But for that i need to generate oauth request which is mandatory.
So for it we need a parameter called "nonce".. which means

Random 64-bit, unsigned number encoded as an ASCII string in decimal format. The nonce/timestamp pair should always be unique to prevent replay attacks.


For genrating nonce value i am writing following code:

Random ran = new Random();
long nonce1 = ran.nextLong();

Long nonce = Math.abs(new Long(nonce1));
String hexString = Long.toHexString(nonce);



Please help me where i am going wrong or can anyone provide with the code??



 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the problem that you are facing with this code is?
 
kalpesh pradhan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Mercs wrote:And the problem that you are facing with this code is?



That its not correctly generating the nonce value... we get invalid signature as response.
 
salvin francis
Bartender
Posts: 1277
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take system time in ms, XOR it with some predefined value say XXX and then take the MD5 hash of the result.

where XXX is any predetermined constant say : "@$#SDFG$#^%E%DSFdfgjhk6875678wqe35REYT"
 
kalpesh pradhan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:Take system time in ms, XOR it with some predefined value say XXX and then take the MD5 hash of the result.

where XXX is any predetermined constant say : "@$#SDFG$#^%E%DSFdfgjhk6875678wqe35REYT"




Can you please give me the java code itself... please its urgent
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this.
 
salvin francis
Bartender
Posts: 1277
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kalpesh,
Post your code here and i could help you complete it.

no problems if its incomplete or wrong...

As i suggested:

1. You need to obtain the system time in milliseconds, you could use the Calendar class for that
2. You need a hard coded (or maybe read from file) value to be XORed
3. You need to calculate MD5 hash of the XORed value:


 
salvin francis
Bartender
Posts: 1277
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also its not necessary that my approach is right, there could be a better approach, keep in mind that calculating an hash is generally not a fast process.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your directions say "decimal format", not "hexadecimal format." Is the correct answer to just use nonce.toString() instead of toHexString() in the original code? Or are the directions wrong?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic