keycloak-service
静的公開メンバ関数 | 全メンバ一覧
org.keycloak.utils.TotpUtils クラス
org.keycloak.utils.TotpUtils 連携図
Collaboration graph

静的公開メンバ関数

static String encode (String totpSecret)
 
static String decode (String totpSecretEncoded)
 
static String qrCode (String totpSecret, RealmModel realm, UserModel user)
 

詳解

著者
Stian Thorgersen

関数詳解

◆ decode()

static String org.keycloak.utils.TotpUtils.decode ( String  totpSecretEncoded)
inlinestatic
48  {
49  String encoded = totpSecretEncoded.replace(" ", "");
50  byte[] bytes = Base32.decode(encoded);
51  return new String(bytes);
52  }

◆ encode()

static String org.keycloak.utils.TotpUtils.encode ( String  totpSecret)
inlinestatic
36  {
37  String encoded = Base32.encode(totpSecret.getBytes());
38  StringBuilder sb = new StringBuilder();
39  for (int i = 0; i < encoded.length(); i += 4) {
40  sb.append(encoded.substring(i, i + 4 < encoded.length() ? i + 4 : encoded.length()));
41  if (i + 4 < encoded.length()) {
42  sb.append(" ");
43  }
44  }
45  return sb.toString();
46  }

◆ qrCode()

static String org.keycloak.utils.TotpUtils.qrCode ( String  totpSecret,
RealmModel  realm,
UserModel  user 
)
inlinestatic
54  {
55  try {
56  String keyUri = realm.getOTPPolicy().getKeyURI(realm, user, totpSecret);
57 
58  int width = 246;
59  int height = 246;
60 
61  QRCodeWriter writer = new QRCodeWriter();
62  final BitMatrix bitMatrix = writer.encode(keyUri, BarcodeFormat.QR_CODE, width, height);
63 
64  ByteArrayOutputStream bos = new ByteArrayOutputStream();
65  MatrixToImageWriter.writeToStream(bitMatrix, "png", bos);
66  bos.close();
67 
68  return Base64.encodeBytes(bos.toByteArray());
69  } catch (Exception e) {
70  throw new RuntimeException(e);
71  }
72  }

このクラス詳解は次のファイルから抽出されました: