title: Error: error:0909006C:PEM routines:get_name:no start line, reason: 'no start line', code: 'ERR_OSSL_PEM_NO_START_LINE'
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const rsaWrapper = require('./rsa-wrapper');
  // generate opened and closed keys for browser and server
  rsaWrapper.generate('server');
  rsaWrapper.generate('client');
  console.log('Keys generated …');</code></pre>
  </div>
  </div>
  </p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!doctype html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
    &lt;title&gt;Encryption/decryption RSA/AES&lt;/title&gt;
    &lt;meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /&gt;
    &lt;link rel="stylesheet" type="text/css" href="/css/style.css" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;div class="container"&gt;
      &lt;div class="text-container"&gt;
        &lt;h2&gt;Server public key&lt;/h2&gt;
        &lt;textarea id="server_public"&gt;&lt;/textarea&gt;
      &lt;/div&gt;
      &lt;div class="text-container"&gt;
        &lt;h2&gt;Client public key&lt;/h2&gt;
        &lt;textarea id="client_public"&gt;&lt;/textarea&gt;
      &lt;/div&gt;
      &lt;div class="text-container"&gt;
        &lt;h2&gt;Client private key&lt;/h2&gt;
        &lt;textarea id="client_private"&gt;&lt;/textarea&gt;
      &lt;/div&gt;
      &lt;div style="clear: both"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="log-container"&gt;
      &lt;h1&gt;Log container&lt;/h1&gt;
      &lt;div id="log" style="padding-top: 20px"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;script src="/socket.io/socket.io.js"&gt; &lt;/script&gt; &lt;script&gt;
      var socket = io();
    &lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>i am getting error, please help me</p>
  <p><a href="https://i.stack.imgur.com/MF6tl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MF6tl.jpg" alt="1" /></a></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const express = require("express");
  const app = express();
  const rsaWrapper = require("./components/rsa-wrapper");
  rsaWrapper.initLoadServerKeys(__dirname);
  rsaWrapper.serverExampleEncrypt();
  
  const http = require("http").Server(app);
  const io = require("socket.io")(http);
  
  // middleware for static processing
  app.use(express.static(__dirname + "/static"));
  // web socket connection event
  io.on("connection", function (socket) {
    console.log("connection");
  });
  http.listen(3000, function () {
    console.log("listening on *:3000");
  });</code></pre>
  </div>
  </div>
  </p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const path = require("path");
  const rsaWrapper = {};
  const fs = require("fs");
  const NodeRSA = require("node-rsa");
  const crypto = require("crypto");
  // open and closed keys generation method
  rsaWrapper.generate = (direction) =&gt; {
    let key = new NodeRSA();
    // 2048 — key length, 65537 open exponent
    key.generateKeyPair(2048, 65537);
    //save keys as pem line in pkcs8
    fs.writeFileSync(
      path.resolve(__dirname, "../keys", direction + ".private.pem"),
      key.exportKey("pkcs8-private-pem")
    );
    fs.writeFileSync(
      path.resolve(__dirname, "../keys", direction + ".public.pem"),
      key.exportKey("pkcs8-public-pem")
    );
    return true;
  };
  // encrypting RSA, using padding OAEP, with nodejs crypto:
  rsaWrapper.encrypt = (publicKey, message) =&gt; {
    let enc = crypto.publicEncrypt({
        key: publicKey,
        padding: crypto.RSA_PKCS1_OAEP_PADDING,
      },
      Buffer.from(message)
    );
    return enc.toString("base64");
  };
  // descrypting RSA, using padding OAEP, with nodejs crypto:
  rsaWrapper.decrypt = (privateKey, message) =&gt; {
    let enc = crypto.privateDecrypt({
        key: privateKey,
        padding: crypto.RSA_PKCS1_OAEP_PADDING,
      },
      Buffer.from(message, "base64")
    );
    return enc.toString();
  };
  // Loading RSA keys from files to variables:
  rsaWrapper.initLoadServerKeys = (basePath) =&gt; {
    rsaWrapper.serverPub = fs.readFileSync(
      path.resolve(basePath, "keys", "server.public.pem")
    );
    rsaWrapper.serverPrivate = fs.readFileSync(
      path.resolve(basePath, "keys", "server.private.pem")
    );
    rsaWrapper.clientPub = fs.readFileSync(
      path.resolve(basePath, "keys", "client.public.pem")
    );
  };
  // Run RSA encryption test scenario. Message is encrypted, log on console in base64 format and message is decrypted and log on console.
  rsaWrapper.serverExampleEncrypt = () =&gt; {
    console.log("Server public encrypting");
    let enc = rsaWrapper.encrypt(rsaWrapper.serverPub, "Server init hello");
    console.log("Server private encrypting …");
    console.log("Encrypted RSA string ", "\n", enc);
    let dec = rsaWrapper.decrypt(rsaWrapper.serverPrivate, enc);
    console.log("Decrypted RSA string …");
    console.log(dec);
  };
  module.exports = rsaWrapper;</code></pre>
  </div>
  </div>
  </p>
  <pre><code>Error: error:0909006C:PEM routines:get_name:no start line
  at Object.rsaWrapper.encrypt (E:\Web Site\NodeJS\Back end website\encryption\components\rsa-wrapper.js:24:20)
  at Object.rsaWrapper.serverExampleEncrypt (E:\Web Site\NodeJS\Back end website\encryption\components\rsa-wrapper.js:59:24)
  at Object.&lt;anonymous&gt; (E:\Web Site\NodeJS\Back end website\encryption\index.js:5:12)
  </code></pre>