Check if secret key to encryot sessions exists,
    generate it otherwise.
334109
def ensure_secret():
    """"""
    home_dir = os.environ['HOME']
    file_name = home_dir + "/.ipcamweb"
    if os.path.exists(file_name):
        with open(file_name, "r") as s_file:
            secret = s_file.readline()
    else:
        secret = os.urandom(24)
        with open(file_name, "w") as s_file:
            secret = s_file.write(secret+"\n")
    return secret
664503
def get_aws_secrets_from_env():  # type: () -> Set[str]
    """"""
    keys = set()
    for env_var in (
        'AWS_SECRET_ACCESS_KEY', 'AWS_SECURITY_TOKEN', 'AWS_SESSION_TOKEN',
    ):
        if env_var in os.environ:
            keys.add(os.environ[env_var])
    return keys
875268
async def generate_psk(self, security_key):
        """"""
        if not self._psk:
            PatchedDTLSSecurityStore.IDENTITY = 'Client_identity'.encode(
                'utf-8')
            PatchedDTLSSecurityStore.KEY = security_key.encode('utf-8')

            command = Gateway().generate_psk(self._psk_id)
            self._psk = await self.request(command)

            PatchedDTLSSecurityStore.IDENTITY = self._psk_id.encode('utf-8')
            PatchedDTLSSecurityStore.KEY = self._psk.encode('utf-8')

            # aiocoap has now cached our psk, so it must be reset.
            # We also no longer need the protocol, so this will clean that up.
            await self._reset_protocol()

        return self._psk
733601
function secretKey(length, options = {}) {
  if (!length || length < 1) {
    return '';
  }

  if (!options.crypto || typeof options.crypto.randomBytes !== 'function') {
    throw new Error('Expecting options.crypto to have a randomBytes function');
  }

  return options.crypto
    .randomBytes(length)
    .toString('base64') // convert format
    .slice(0, length); // return required number of characters
}
654642
def _generate_session_id(self):
        """"""

        while True:
            rand = os.urandom(16)
            now = time.time()
            secret_key = self._config.secret_key
            session_id = hashlib.sha1(("%s%s%s%s" % (rand, now, utils.safestr(web.ctx.ip), secret_key)).encode("utf-8"))
            session_id = session_id.hexdigest()
            if session_id not in self.store:
                break
        return session_id
1140424
def key_verify(rsakey, signature, message, digest):
    """"""
    padding = _asymmetric.padding.PKCS1v15()
    if isinstance(rsakey, _asymmetric.rsa.RSAPrivateKey):
        rsakey = rsakey.public_key()

    try:
        rsakey.verify(signature, message, padding, digest)
    except Exception as e:
        return False
    else:
        return True
769630
def _verifyHostKey(self, hostKey, fingerprint):
        
        if fingerprint in self.knownHosts:
            return defer.succeed(True)
        return defer.fail(UnknownHostKey(hostKey, fingerprint))
231423
protected function verifyInternalKey()
    {
        // if we are running in stateless mode, there's no need for an IPC key.
        if ($this->isStateless()) {
            $this->setInternalKey('');
              return;
        }

        if (trim($this->getInternalKey()) == '') {
            if (session_id() != '') { /*if programmer already started session, use it*/
                $this->setInternalKey("/tmp/" . session_id());
            } else {
                $this->setInternalKey("/tmp/". $this->generate_name());
            }
        }
    }
1247953
def _update_aes(self):
        '''
        
        '''
        if salt.master.SMaster.secrets['aes']['secret'].value != self.crypticle.key_string:
            self.crypticle = salt.crypt.Crypticle(self.opts, salt.master.SMaster.secrets['aes']['secret'].value)
            return True
        return False
254715
public static function isLive()
    {
        if (preg_match("/^(live_private_|test_private_)/", self::$apiKey)) {
            return true;
        } elseif (preg_match("/^sandbox_private_/", self::$apiKey)) {
            return false;
        } else {
            throw new Error\InvalidApiKey('Set correct secret key.');
        }
    }
695188
def get_secret(
        end_state: NettingChannelEndState,
        secrethash: SecretHash,
) -> Optional[Secret]:
    """"""
    partial_unlock_proof = end_state.secrethashes_to_unlockedlocks.get(secrethash)

    if partial_unlock_proof is None:
        partial_unlock_proof = end_state.secrethashes_to_onchain_unlockedlocks.get(secrethash)

    if partial_unlock_proof is not None:
        return partial_unlock_proof.secret

    return None
1193015
def prepare(session_data={}, #pylint: disable=dangerous-default-value
                passphrase=None):
        
        if passphrase is None:
            passphrase = settings.DJAODJIN_SECRET_KEY
        return encode(session_data, passphrase,
            json_encoder=crypt.JSONEncoder)
248691
def generate_session_token(secret_key, **payload):
    
    return jwt.encode(payload, secret_key, algorithm=token_encryption_algorithm()).decode('utf-8')
311883
def check_key_file(user,
                   source,
                   config='.ssh/authorized_keys',
                   saltenv='base',
                   fingerprint_hash_type=None):
    '''
    
    '''
    keyfile = __salt__['cp.cache_file'](source, saltenv)
    if not keyfile:
        return {}
    s_keys = _validate_keys(keyfile, fingerprint_hash_type)
    if not s_keys:
        err = 'No keys detected in {0}. Is file properly ' \
              'formatted?'.format(source)
        log.error(err)
        __context__['ssh_auth.error'] = err
        return {}
    else:
        ret = {}
        for key in s_keys:
            ret[key] = check_key(
                user,
                key,
                s_keys[key]['enc'],
                s_keys[key]['comment'],
                s_keys[key]['options'],
                config=config,
                fingerprint_hash_type=fingerprint_hash_type)
        return ret
1049872
def has_no_password(gpg_secret_keyid):
    """"""

    if gnupg is None:
        return False

    gpg = gnupg.GPG()
    s = gpg.sign("", keyid=gpg_secret_keyid, passphrase="")

    try:
        return s.status == "signature created"
    except AttributeError:
        # This may happen on Windows
        if hasattr(s, "stderr"):
            return "GOOD_PASSPHRASE" in s.stderr
511981
def read_session_token(secret_key, token):
    
    return jwt.decode(token.encode('utf-8'), secret_key,
        algorithms=[token_encryption_algorithm()]
    )
1333405
def secret(self, s):
        
        s = parseable_str(s)
        for f in [self.private_key, self.hierarchical_key]:
            v = f(s)
            if v:
                return v