MCPcopy Index your code
hub / github.com/bcrypt-ruby/bcrypt-ruby / encode_base64

Method encode_base64

ext/jruby/bcrypt_jruby/BCrypt.java:387–417  ·  view source on GitHub ↗

Encode a byte array using bcrypt's slightly-modified base64 encoding scheme. Note that this is not compatible with the standard MIME-base64 encoding. @param d the byte array to encode @param len the number of bytes to encode @param rs the destination buffer for the base64-encoded s

(byte d[], int len, StringBuilder rs)

Source from the content-addressed store, hash-verified

385 * @exception IllegalArgumentException if the length is invalid
386 */
387 static void encode_base64(byte d[], int len, StringBuilder rs)
388 throws IllegalArgumentException {
389 int off = 0;
390 int c1, c2;
391
392 if (len <= 0 || len > d.length) {
393 throw new IllegalArgumentException("Invalid len");
394 }
395
396 while (off < len) {
397 c1 = d[off++] & 0xff;
398 rs.append(base64_code[(c1 >> 2) & 0x3f]);
399 c1 = (c1 & 0x03) << 4;
400 if (off >= len) {
401 rs.append(base64_code[c1 & 0x3f]);
402 break;
403 }
404 c2 = d[off++] & 0xff;
405 c1 |= (c2 >> 4) & 0x0f;
406 rs.append(base64_code[c1 & 0x3f]);
407 c1 = (c2 & 0x0f) << 2;
408 if (off >= len) {
409 rs.append(base64_code[c1 & 0x3f]);
410 break;
411 }
412 c2 = d[off++] & 0xff;
413 c1 |= (c2 >> 6) & 0x03;
414 rs.append(base64_code[c1 & 0x3f]);
415 rs.append(base64_code[c2 & 0x3f]);
416 }
417 }
418
419 /**
420 * Look up the 3 bits base64-encoded by the specified character,

Callers 2

hashpwMethod · 0.95
gensaltMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected