Java生成GoEasy-OTP - GoEasy

Java生成GoEasyOTP

    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

系统毫秒数:1490325990593

测试结果:

GoEasy-otp:+rOKqbTZioistsdMrhon0A==

results matching ""

    No results matching ""