async function fromJwk(jwkey, format, {outputPublic, compact=false, passphrase = '', encOptions}){
  const orgType = getJwkType(jwkey);
  let type = (typeof outputPublic === 'boolean' && outputPublic) ? 'public' : orgType;

  let decoded;
  if (jwkey.kty === 'EC') {
    decoded = asn1ec.fromJWK(jwkey, type, compact);
  }
  else if (jwkey.kty === 'RSA'){
    decoded = asn1rsa.fromJwk(jwkey, type);
  }

  let binKey;
  if (type === 'public') {
    binKey = SubjectPublicKeyInfo.encode(decoded, 'der');
  }
  else {
    binKey = OneAsymmetricKey.encode(decoded, 'der');
    if(passphrase.length > 0){
      binKey = await encryptEncryptedPrivateKeyInfo(binKey, passphrase, encOptions);
      type = 'encryptedPrivate';
    }
  }
  binKey = new Uint8Array(binKey);

  return (format === 'pem') ? jseu.formatter.binToPem(binKey, type) : binKey;
}
/**
 * Convert jwk to spki/pkcs8 in string or binary format.
 * @param jwkey
 * @param outputPublic {boolean} : derive public key from private key when true
 * @param format {string} : 'pem' or 'der'
 * @param compact {boolean} : 'true' or 'false' for EC public key compressed representation in der/pem
 * @param passphrase
 * @param encOptions
 * @return {Uint8Array}
 */
Convert jwk to spki/pkcs8 in string or binary format.
Convert jwk to spki / pkcs8 in string or binary format .
async function fromJwk(jwkey, format, {outputPublic, compact=false, passphrase = '', encOptions}){
  const orgType = getJwkType(jwkey);
  let type = (typeof outputPublic === 'boolean' && outputPublic) ? 'public' : orgType;
  let decoded;
  if (jwkey.kty === 'EC') {
    decoded = asn1ec.fromJWK(jwkey, type, compact);
  }
  else if (jwkey.kty === 'RSA'){
    decoded = asn1rsa.fromJwk(jwkey, type);
  }
  let binKey;
  if (type === 'public') {
    binKey = SubjectPublicKeyInfo.encode(decoded, 'der');
  }
  else {
    binKey = OneAsymmetricKey.encode(decoded, 'der');
    if(passphrase.length > 0){
      binKey = await encryptEncryptedPrivateKeyInfo(binKey, passphrase, encOptions);
      type = 'encryptedPrivate';
    }
  }
  binKey = new Uint8Array(binKey);
  return (format === 'pem') ? jseu.formatter.binToPem(binKey, type) : binKey;
}
async function fromJwk ( jwkey , format , { outputPublic , compact = false , passphrase = '' , encOptions } ) { const orgType = getJwkType ( jwkey ) ; let type = ( typeof outputPublic === 'boolean' && outputPublic ) ? 'public' : orgType ; let decoded ; if ( jwkey . kty === 'EC' ) { decoded = asn1ec . fromJWK ( jwkey , type , compact ) ; } else if ( jwkey . kty === 'RSA' ) { decoded = asn1rsa . fromJwk ( jwkey , type ) ; } let binKey ; if ( type === 'public' ) { binKey = SubjectPublicKeyInfo . encode ( decoded , 'der' ) ; } else { binKey = OneAsymmetricKey . encode ( decoded , 'der' ) ; if ( passphrase . length > 0 ) { binKey = await encryptEncryptedPrivateKeyInfo ( binKey , passphrase , encOptions ) ; type = 'encryptedPrivate' ; } } binKey = new Uint8Array ( binKey ) ; return ( format === 'pem' ) ? jseu . formatter . binToPem ( binKey , type ) : binKey ; }
Convert jwk to spki/pkcs8 in string or binary format.
Convert jwk to spki / pkcs8 in string or binary format .