def gen(id_=None, keysize=2048):
 if (id_ is None):
  id_ = hashlib.sha512(os.urandom(32)).hexdigest()
 else:
  id_ = clean.filename(id_)
 ret = {'priv': '', 'pub': ''}
 priv = salt.crypt.gen_keys(__opts__['pki_dir'], id_, keysize)
 pub = '{0}.pub'.format(priv[:priv.rindex('.')])
 with salt.utils.fopen(priv) as fp_:
  ret['priv'] = fp_.read()
 with salt.utils.fopen(pub) as fp_:
  ret['pub'] = fp_.read()
 os.remove(priv)
 os.remove(pub)
 return ret

def gen ( id_ = None , keysize = 2048 ) : if ( id_ is None ) : id_ = hashlib . sha512 ( os . urandom ( 32 ) ) . hexdigest ( ) else : id_ = clean . filename ( id_ ) ret = { 'priv' : '' , 'pub' : '' } priv = salt . crypt . gen_keys ( __opts__ [ 'pki_dir' ] , id_ , keysize ) pub = '{0}.pub' . format ( priv [ : priv . rindex ( '.' ) ] ) with salt . utils . fopen ( priv ) as fp_ : ret [ 'priv' ] = fp_ . read ( ) with salt . utils . fopen ( pub ) as fp_ : ret [ 'pub' ] = fp_ . read ( ) os . remove ( priv ) os . remove ( pub ) return ret
generate a key pair .