Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to generate OTP in java and encrypt it

What is the best way to generate an OTP (One Time Password or a random short string) and encrypt it in java? I'm familiar with MD5, sha256. But I'm guessing that is not enough since there are still better ways to generate an OTP string and some uses an algorithm which I am not that familiar with on how it works. For example the RFC 6238 on TOTP: Time-Based One-Time Password Algorithm. which is used for OTP. Will this create a "code" that will use the current time it was created?

Also found this example online on encrypting strings using java: encrypting string in java

Basically what i'm trying to achieve here is to securely generate a code that is less prone to be predicted by hackers and secure it. so maybe i'll generate a code using the current date and time and the age of the user.

So if anyone would be able to guide me on which direction I should focus if I want the best way to generate a short length "code" and encrypt it. Much like using an algorithm of sort. a few link would be helpful.

like image 421
magicianiam Avatar asked Oct 31 '22 19:10

magicianiam


1 Answers

See crypto it is very secure because for an attacker it will take much time to decrypt it and also it is the slowest of all encryption algo's which is best in terms of security

like image 83
Sudhanshu Gaur Avatar answered Nov 02 '22 09:11

Sudhanshu Gaur