GoEasy-OTP > Java生成GoEasy-OTP
 

GoEasy-OTP - Java生成GoEasy-OTP

Java

    public static String goEasyOTP(String secretKey) {
        try {
            String otp = "000" + System.currentTimeMillis();
            SecretKeySpec key = new SecretKeySpec(secretKey.getBytes(), "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
            byte[] otpBytes = otp.getBytes();
            cipher.init(Cipher.ENCRYPT_MODE, key);
            byte[] encryptedOTP = cipher.doFinal(otpBytes);
            otp = new BASE64Encoder().encode(encryptedOTP);
            return otp;
        } catch (Exception e) {
            throw new IllegalStateException("Failed to generate GoEasy-OTP.", e);
        }
    }

验证OTP生成结果

测试参数:

secret key:86726e4356dce2d3

系统毫秒数:0001490325990593

测试结果:

GoEasy-otp:+rOKqbTZioistsdMrhon0A==

相关链接:

什么是GoEasy-OTP?
如何使用GoEasy-OTP?
验证GoEasy-OTP生成结果
Java生成GoEasy-OTP
PHP生成GoEasy-OTP
Python生成GoEasy-OTP
Ruby生成GoEasy-OTP
C#生成GoEasy-OTP

results matching ""

    No results matching ""