MCPcopy
hub / github.com/dcodeIO/bcrypt.js / base64_encode

Function base64_encode

index.js:425–453  ·  view source on GitHub ↗

* Encodes a byte array to base64 with up to len bytes of input. * @param {!Array. } b Byte array * @param {number} len Maximum input length * @returns {string} * @inner

(b, len)

Source from the content-addressed store, hash-verified

423 * @inner
424 */
425function base64_encode(b, len) {
426 var off = 0,
427 rs = [],
428 c1,
429 c2;
430 if (len <= 0 || len > b.length) throw Error("Illegal len: " + len);
431 while (off < len) {
432 c1 = b[off++] & 0xff;
433 rs.push(BASE64_CODE[(c1 >> 2) & 0x3f]);
434 c1 = (c1 & 0x03) << 4;
435 if (off >= len) {
436 rs.push(BASE64_CODE[c1 & 0x3f]);
437 break;
438 }
439 c2 = b[off++] & 0xff;
440 c1 |= (c2 >> 4) & 0x0f;
441 rs.push(BASE64_CODE[c1 & 0x3f]);
442 c1 = (c2 & 0x0f) << 2;
443 if (off >= len) {
444 rs.push(BASE64_CODE[c1 & 0x3f]);
445 break;
446 }
447 c2 = b[off++] & 0xff;
448 c1 |= (c2 >> 6) & 0x03;
449 rs.push(BASE64_CODE[c1 & 0x3f]);
450 rs.push(BASE64_CODE[c2 & 0x3f]);
451 }
452 return rs.join("");
453}
454
455/**
456 * Decodes a base64 encoded string to up to len bytes of output.

Callers 3

genSaltSyncFunction · 0.85
finishFunction · 0.85
encodeBase64Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected