I have a situation where I need time based OTP.

But most of the examples and cases I have seen, uses same key to create and check otp.

But I need something different. I want to create OTP using a public key, so that it can only be checked/decrypted using private key only.

Is there any method like this?

  • 1
    Why do you want this? What is the actual problem you are trying to solve?
    – Sjoerd
    May 24, 2017 at 11:11
  • Because OTP will be generated at client's side, and I will be using that OTP for further encryption
    – kadamb
    May 24, 2017 at 11:20
  • Why don't you use current system time ?
    – ifexploit
    May 24, 2017 at 11:26
  • Because I need to decrypt it too, if I use the current system time, I won't have that information at the server side to decrypt it.
    – kadamb
    May 24, 2017 at 11:35
  • 1
    Encrypt the file and the current time both using the public key, the same can be decrypted at the server end.
    – ifexploit
    May 24, 2017 at 13:37

2 Answers 2


In case you are talking about a One Time Password there is a simple reason, why TOTP-Algorithms are using a symmetric key on the client/device and the server side.

If you take a look at HOTP-TOTP (RFC6238), it is derived fro HOTP-OTP (RFC4226), the event based OTP algorithm. This was specified in 2005. The first smartphone arived in 2007.

So what? The OTP algorithms are designed to work with hardware devices. These hardware devices have a display, so that the user can punch in the one time password. During the generation of the one time password the RFC defines a truncation method, so that the user is actually able to punch in a limited set of characters. The output of HMAC-SHA1 is 20 bytes hexcode. Noone wants to enter this as a one time password.

To be able to do assymmetric cryptography you can not use any truncation function. Otherwise the public key would not be able to verify the signature. The private key would not be able to decrypt the message. The data to transfer with assymmetric keys would be much larger - 1024 bit, 2048 bit... Again, the user would have to enter manually a very long one time password.

Well, if the client transmits this data electonically you would not have to truncate it. But then we are again not talking about one time passwords but about publy key crypto or client certificate based authentication.

So in the end it is all about human readability and truncation.


I have a situation where I need time based OTP.

First let's recollect the basis of Time-based OTP (or) Time-Synchronized OTP. A TOTP uses TIME (real-time clock) of the client in the process of OTP generation. So, it is safe to say that the "time" factor is a public key and a private key.

But most of the examples and cases I have seen, uses same key to create and check otp

This query completely contradicts the TOTP concept, correct me if I'm wrong. Later, you claim you need something different, If I understood this correctly, You want the OTP to be generated using Time of the client, The server is aware of the client's local time... This way the OTP generated by user (entered in client) is authenticated by the server. But you want it checked by a private key which is nothing but the server's synchronization of client local-time. So, please stop referring public key/private key with TOTP as

Time (local-time of client) is used in generation and checking of the OTP itself.

edit: (after reading comments) The Server needs to have a synchronization with the client local time, or the TOTP concept fails... I cannot stress the facts beyond this.

  • "The Server needs to have a synchronization with the client local time"...yeah I am aware of that, I have figured out a solution, I will put my answer, after confirming it.
    – kadamb
    May 24, 2017 at 11:51
  • You just might be inventing a new security solution with your approach, I am looking forward to it!
    – Adib N
    May 24, 2017 at 12:27
  • 1
    I don't understand this answer at all. Time synchronisation nothing more than PKI checking? I know it's been a while since it was written, but maybe @AdibN can clarify further.
    – Ralph
    Jan 5 at 11:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .