examples/generateAndLoadKeysIntoKvm.js
function loadKeysIntoMap(org, cb) {
  var uuid = uuidV4();
  var re = new RegExp('(?:\r\n|\r|\n)', 'g');
  var keypair = new NodeRSA({b: opt.options.keystrength});
  var publicKeyPem = keypair.exportKey('pkcs8-public-pem').replace(re,'\\n');
  var privateKeyPem = keypair.exportKey('pkcs8-private-pem').replace(re,'\\n');
  var options = {
        env: opt.options.env,
        kvm: opt.options.privkeysmap,
        key: 'private__' + uuid,
        value: privateKeyPem
      };
  common.logWrite(sprintf('provisioning new key %s', uuid));
  org.kvms.put(options, function(e, result){
    if (e) return cb(e, result);
    options.kvm = opt.options.pubkeysmap;
    options.key = 'public__' + uuid;
    options.value = publicKeyPem;
    org.kvms.put(options, function(e, result){
      if (e) return cb(e, result);
      options.kvm = opt.options.kidmap;
      options.key = 'currentKid';
      options.value = uuid;
      org.kvms.put(options, function(e, result){
        if (e) return cb(e, result);
        cb(null, result);
      });
    });
  });
}
function loadKeysIntoMap(org, cb) {
  var uuid = uuidV4();
  var re = new RegExp('(?:\r\n|\r|\n)', 'g');
  var keypair = new NodeRSA({b: opt.options.keystrength});
  var publicKeyPem = keypair.exportKey('pkcs8-public-pem').replace(re,'\\n');
  var privateKeyPem = keypair.exportKey('pkcs8-private-pem').replace(re,'\\n');
  var options = {
        env: opt.options.env,
        kvm: opt.options.privkeysmap,
        key: 'private__' + uuid,
        value: privateKeyPem
      };
  common.logWrite(sprintf('provisioning new key %s', uuid));
  org.kvms.put(options, function(e, result){
    if (e) return cb(e, result);
    options.kvm = opt.options.pubkeysmap;
    options.key = 'public__' + uuid;
    options.value = publicKeyPem;
    org.kvms.put(options, function(e, result){
      if (e) return cb(e, result);
      options.kvm = opt.options.kidmap;
      options.key = 'currentKid';
      options.value = uuid;
      org.kvms.put(options, function(e, result){
        if (e) return cb(e, result);
        cb(null, result);
      });
    });
  });
}
========================================================