keycloak
静的公開メンバ関数 | 静的非公開変数類 | 全メンバ一覧
org.keycloak.models.utils.Base32 クラス
org.keycloak.models.utils.Base32 連携図
Collaboration graph

静的公開メンバ関数

static String encode (final byte[] bytes)
 
static byte [] decode (final String base32)
 

静的非公開変数類

static final String base32Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
 
static final int [] base32Lookup
 

詳解

Base32 - encodes and decodes RFC3548 Base32 (see http://www.faqs.org/rfcs/rfc3548.html )

著者
Robert Kaye
Gordon Mohr

関数詳解

◆ decode()

static byte [] org.keycloak.models.utils.Base32.decode ( final String  base32)
inlinestatic

Decodes the given Base32 String to a raw byte array.

引数
base32
戻り値
Decoded base32 String as a raw byte array.
87  {
88  int i, index, lookup, offset, digit;
89  byte[] bytes = new byte[base32.length() * 5 / 8];
90 
91  for (i = 0, index = 0, offset = 0; i < base32.length(); i++) {
92  lookup = base32.charAt(i) - '0';
93 
94  /* Skip chars outside the lookup table */
95  if (lookup < 0 || lookup >= base32Lookup.length) {
96  continue;
97  }
98 
99  digit = base32Lookup[lookup];
100 
101  /* If this digit is not in the table, ignore it */
102  if (digit == 0xFF) {
103  continue;
104  }
105 
106  if (index <= 3) {
107  index = (index + 5) % 8;
108  if (index == 0) {
109  bytes[offset] |= digit;
110  offset++;
111  if (offset >= bytes.length)
112  break;
113  } else {
114  bytes[offset] |= digit << (8 - index);
115  }
116  } else {
117  index = (index + 5) % 8;
118  bytes[offset] |= (digit >>> index);
119  offset++;
120 
121  if (offset >= bytes.length) {
122  break;
123  }
124  bytes[offset] |= digit << (8 - index);
125  }
126  }
127  return bytes;
128  }
static final int [] base32Lookup
Definition: Base32.java:35

◆ encode()

static String org.keycloak.models.utils.Base32.encode ( final byte []  bytes)
inlinestatic

Encodes byte array to Base32 String.

引数
bytesBytes to encode.
戻り値
Encoded byte array bytes as a String.
48  {
49  int i = 0, index = 0, digit = 0;
50  int currByte, nextByte;
51  StringBuffer base32 = new StringBuffer((bytes.length + 7) * 8 / 5);
52 
53  while (i < bytes.length) {
54  currByte = (bytes[i] >= 0) ? bytes[i] : (bytes[i] + 256);
55 
56  /* Is the current digit going to span a byte boundary? */
57  if (index > 3) {
58  if ((i + 1) < bytes.length) {
59  nextByte = (bytes[i + 1] >= 0) ? bytes[i + 1] : (bytes[i + 1] + 256);
60  } else {
61  nextByte = 0;
62  }
63 
64  digit = currByte & (0xFF >> index);
65  index = (index + 5) % 8;
66  digit <<= index;
67  digit |= nextByte >> (8 - index);
68  i++;
69  } else {
70  digit = (currByte >> (8 - (index + 5))) & 0x1F;
71  index = (index + 5) % 8;
72  if (index == 0)
73  i++;
74  }
75  base32.append(base32Chars.charAt(digit));
76  }
77 
78  return base32.toString();
79  }
static final String base32Chars
Definition: Base32.java:34

メンバ詳解

◆ base32Chars

final String org.keycloak.models.utils.Base32.base32Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
staticprivate

◆ base32Lookup

final int [] org.keycloak.models.utils.Base32.base32Lookup
staticprivate
初期値:
= { 0xFF, 0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01,
0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
0x15, 0x16, 0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }

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