import me.sniggle.security.common.totp.*; public class SimpleExample { public static void main(String[] args) { TOTPGenerator totpGenerator = new TOTPGenerator(); totpGenerator.init(); byte[] secret = totpGenerator.generateSecretKey(); String otp = totpGenerator.generateOTP(secret); System.out.println("Token: " + otp); } }
import me.sniggle.security.common.*; import me.sniggle.security.common.totp.*; import me.sniggle.security.common.qr.*; public class GenerateQRCodeImageExample { public static void main(String[] args) throws Exception { TOTPGenerator totpGenerator = new TOTPGenerator(); totpGenerator.init(); byte[] secretKey = totpGenerator.generateSecretKey(); QRCodeGenerator qrCodeGenerator = new QRCodeGenerator(); byte[] pngImageData = qrCodeGenerator.generateQRCode(TwoFactorTypes.TOTP, "myservice", "useraccount@myservice.com", secretKey, Collections.emptyMap()); try( OutputStream out = new FileOutputStream(Paths.get("/qr-code.png")) ) { out.write(pngImageData); } System.out.println("QR Code image written to: /qr-code.png"); } }
There was an error while loading. Please reload this page.