async export(format = 'jwk', options={}){
    // global assertion
    if(['pem', 'der', 'jwk', 'oct'].indexOf(format) < 0) throw new Error('UnsupportedFormat');

    // return 'as is' without passphrase when nothing is given as 'options'
    // only for the case to export der key from der key (considering encrypted key). expect to be called from getter
    if((format === 'der' || format === 'pem') && Object.keys(options).length === 0
      && this._isEncrypted === true && this._type === 'private' && this._current.der)
    {
      return (format === 'pem') ? jseu.formatter.binToPem(this._der, 'encryptedPrivate') : this._der;
    }
    if(this._isEncrypted) throw new Error('DecryptionRequired');

    let jwkey;
    // first converted to jwk
    if(this._current.jwk){
      jwkey = this._jwk;
    }
    else {
      // options.type is not specified here to import jwk
      if(this._current.oct) {
        jwkey = await toJwkFrom('oct', this._oct.key, {namedCurve: this._oct.namedCurve});
      }
      else if(this._current.der){
        jwkey = await toJwkFrom('der', this._der);
      }
      else throw new Error('InvalidStatus');

      this._setJwk(jwkey); // store jwk if the exiting private key is not encrypted
    }

    // then export as the key in intended format
    if (format === 'der' || format === 'pem') {
      if(typeof options.encryptParams === 'undefined') options.encryptParams = {};
      return await fromJwkTo(format, jwkey, {
        outputPublic: options.outputPublic,
        compact: options.compact,
        passphrase: options.encryptParams.passphrase,
        encOptions: options.encryptParams
      });
    }
    else if (format === 'oct') {
      return await fromJwkTo(format, jwkey, {
        outputPublic: options.outputPublic,
        format: options.output,
        compact: options.compact
      });
    }
    else return jwkey;
  }
/**
   * Wrapper of converter. Imported key must be basically decrypted except the case where the key is exported as-is.
   * @param format {string}: 'jwk', 'pem', 'der' or 'oct'
   * @param options {object}:
   * - options.outputPublic {boolean}: (optional) [format = *]
   *     derive public key from private key when options.outputPublic = true.
   * - options.compact {boolean}: (optional) [format = 'der', 'pem' or 'oct', only for EC key]
   *     generate compressed EC public key.
   * - options.encryptParams {object}: (optional) [format = 'der' or 'pem'] options to generate encrypted der/pem private key.
   *     * encryptParams.passphrase {string}: (mandatory if encOption is specified).
   *          (re-)generate encrypted der/pem with the given passphrase
   *     * encryptParams.algorithm {string}: (optional) 'pbes2' (default), 'pbeWithMD5AndDES-CBC' or 'pbeWithSHA1AndDES'
   *     * encryptParams.prf {string}: (optional) [encOptions.algorithm = 'pbes2'],
   *         'hmacWithSHA256' (default), 'hmacWithSHA384', 'hmacWithSHA512' or 'hmacWithSHA1'
   *     * encryptParams.iterationCount {integer}: 2048 (default)
   *     * encryptParams.cipher {string}: 'aes256-cbc' (default), 'aes128-cbc' or 'des-ede3-cbc'
   * @return {Promise<*>}
   */
Wrapper of converter. Imported key must be basically decrypted except the case where the key is exported as-is.
Wrapper of converter . Imported key must be basically decrypted except the case where the key is exported as - is .
async export(format = 'jwk', options={}){
    if(['pem', 'der', 'jwk', 'oct'].indexOf(format) < 0) throw new Error('UnsupportedFormat');
    if((format === 'der' || format === 'pem') && Object.keys(options).length === 0
      && this._isEncrypted === true && this._type === 'private' && this._current.der)
    {
      return (format === 'pem') ? jseu.formatter.binToPem(this._der, 'encryptedPrivate') : this._der;
    }
    if(this._isEncrypted) throw new Error('DecryptionRequired');
    let jwkey;
    if(this._current.jwk){
      jwkey = this._jwk;
    }
    else {
      if(this._current.oct) {
        jwkey = await toJwkFrom('oct', this._oct.key, {namedCurve: this._oct.namedCurve});
      }
      else if(this._current.der){
        jwkey = await toJwkFrom('der', this._der);
      }
      else throw new Error('InvalidStatus');
      this._setJwk(jwkey); 
    }
    if (format === 'der' || format === 'pem') {
      if(typeof options.encryptParams === 'undefined') options.encryptParams = {};
      return await fromJwkTo(format, jwkey, {
        outputPublic: options.outputPublic,
        compact: options.compact,
        passphrase: options.encryptParams.passphrase,
        encOptions: options.encryptParams
      });
    }
    else if (format === 'oct') {
      return await fromJwkTo(format, jwkey, {
        outputPublic: options.outputPublic,
        format: options.output,
        compact: options.compact
      });
    }
    else return jwkey;
  }
async export ( format = 'jwk' , options = { } ) { if ( [ 'pem' , 'der' , 'jwk' , 'oct' ] . indexOf ( format ) < 0 ) throw new Error ( 'UnsupportedFormat' ) ; if ( ( format === 'der' || format === 'pem' ) && Object . keys ( options ) . length === 0 && this . _isEncrypted === true && this . _type === 'private' && this . _current . der ) { return ( format === 'pem' ) ? jseu . formatter . binToPem ( this . _der , 'encryptedPrivate' ) : this . _der ; } if ( this . _isEncrypted ) throw new Error ( 'DecryptionRequired' ) ; let jwkey ; if ( this . _current . jwk ) { jwkey = this . _jwk ; } else { if ( this . _current . oct ) { jwkey = await toJwkFrom ( 'oct' , this . _oct . key , { namedCurve : this . _oct . namedCurve } ) ; } else if ( this . _current . der ) { jwkey = await toJwkFrom ( 'der' , this . _der ) ; } else throw new Error ( 'InvalidStatus' ) ; this . _setJwk ( jwkey ) ; } if ( format === 'der' || format === 'pem' ) { if ( typeof options . encryptParams === 'undefined' ) options . encryptParams = { } ; return await fromJwkTo ( format , jwkey , { outputPublic : options . outputPublic , compact : options . compact , passphrase : options . encryptParams . passphrase , encOptions : options . encryptParams } ) ; } else if ( format === 'oct' ) { return await fromJwkTo ( format , jwkey , { outputPublic : options . outputPublic , format : options . output , compact : options . compact } ) ; } else return jwkey ; }
Wrapper of converter.
Wrapper of converter .
// global assertion // return 'as is' without passphrase when nothing is given as 'options' // only for the case to export der key from der key (considering encrypted key). expect to be called from getter // first converted to jwk // options.type is not specified here to import jwk // store jwk if the exiting private key is not encrypted // then export as the key in intended format