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

Method pemToDER

modules/crypt/etc/transform.js:24–52  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

22
23class Transform {
24 static pemToDER(source) {
25 if ("string" !== typeof source)
26 source = String.fromArrayBuffer(source);
27
28 let start = source.indexOf("-----BEGIN CERTIFICATE-----"), end = -1;
29 if (start >= 0) {
30 start += 28;
31 end = source.indexOf("-----END CERTIFICATE-----", start)
32 }
33 else {
34 start = source.indexOf("-----BEGIN RSA PRIVATE KEY-----");
35 if (start >= 0) {
36 start += 32;
37 end = source.indexOf("-----END RSA PRIVATE KEY-----", start)
38 }
39 else {
40 start = source.indexOf("-----BEGIN PRIVATE KEY-----");
41 if (start >= 0) {
42 start += 28;
43 end = source.indexOf("-----END PRIVATE KEY-----", start)
44 }
45 }
46 }
47
48 if (end < 0)
49 throw new Error("no delimiter");
50
51 return Uint8Array.fromBase64(source.slice(start, end)).buffer;
52 }
53 static privateKeyToPrivateKeyInfo(source, id = [1, 2, 840, 113549, 1, 1, 1] /* // PKCS#1 OID */) { // https://datatracker.ietf.org/doc/html/rfc5208#section-5
54 return BER.encode([
55 0x30,

Callers 1

extractOneMethod · 0.80

Calls 3

fromBase64Method · 0.80
fromArrayBufferMethod · 0.65
sliceMethod · 0.65

Tested by

no test coverage detected