MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / pkcs12gen

Function pkcs12gen

modules/crypt/etc/pkcs8.js:46–81  ·  view source on GitHub ↗
(P, S, c, dkLen, hash, v)

Source from the content-addressed store, hash-verified

44}
45
46function pkcs12gen(P, S, c, dkLen, hash, v)
47{
48 // assuming dkLen <= hash.outputSize
49 var h = new hash();
50
51 // D = id || id || ...
52 var D = new Uint8Array(v);
53 D.fill(1); // id = 1 for key material
54 h.update(D.buffer);
55
56 var len = v * howmany(S.byteLength, v), l;
57 for (l = 0; l + S.byteLength < len; l += S.byteLength)
58 h.update(S);
59 if (len - l > 0)
60 h.update(S.slice(0, len - l));
61
62 // convert the string to a wchar string for password
63 var UP = new Uint8Array((P.length + 1) * 2);
64 for (var i = 0, j = 0; i < P.length; i++) {
65 UP[j++] = 0;
66 UP[j++] = P.charCodeAt(i);
67 }
68 UP[j++] = 0;
69 UP[j] = 0;
70 var buf = UP.buffer;
71 len = v * howmany(buf.byteLength, v);
72 for (l = 0; l + buf.byteLength < len; l += buf.byteLength)
73 h.update(buf);
74 if (len - l > 0)
75 h.update(buf.slice(0, len - l));
76
77 var dk = h.close();
78 for (c -= 1; --c >= 0;)
79 dk = h.process(dk);
80 return dk.slice(0, dkLen);
81}
82
83export default class PKCS8 {
84 static parse(buf) {

Callers 1

decryptMethod · 0.85

Calls 6

howmanyFunction · 0.85
fillMethod · 0.65
sliceMethod · 0.65
closeMethod · 0.65
updateMethod · 0.45
processMethod · 0.45

Tested by

no test coverage detected