-
Notifications
You must be signed in to change notification settings - Fork 1
Examples
Iulius edited this page Oct 20, 2015
·
1 revision
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", "[email protected]", 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");
}
}