@/utils/utils#getDeviceName JavaScript Examples

The following examples show how to use @/utils/utils#getDeviceName. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: auth.js    From lx-music-mobile with Apache License 2.0 6 votes vote down vote up
codeAuth = async(host, port, serverId, authCode) => {
  let key = ''.padStart(16, Buffer.from(authCode).toString('hex'))
  const iv = Buffer.from(key.split('').reverse().join('')).toString('base64')
  key = Buffer.from(key).toString('base64')
  const msg = aesEncrypt(SYNC_CODE.authMsg + await getDeviceName(), key, iv)
  return request(`http://${host}:${port}/ah`, { headers: { m: msg } }).then(text => {
    // console.log(text)
    let msg
    try {
      msg = aesDecrypt(text, key, iv)
    } catch (err) {
      log.error('[auth] codeAuth decryptMsg error', err.message)
      throw new Error(SYNC_CODE.authFailed)
    }
    if (!msg) return Promise.reject(new Error(SYNC_CODE.authFailed))
    const info = JSON.parse(msg)
    setSyncAuthKey(serverId, info)
    return info
  })
}
Example #2
Source File: auth.js    From lx-music-mobile with Apache License 2.0 6 votes vote down vote up
keyAuth = async(host, port, keyInfo) => {
  const msg = aesEncrypt(SYNC_CODE.authMsg + await getDeviceName(), keyInfo.key, keyInfo.iv)
  return request(`http://${host}:${port}/ah`, { headers: { i: keyInfo.clientId, m: msg } }).then(text => {
    let msg
    try {
      msg = aesDecrypt(text, keyInfo.key, keyInfo.iv)
    } catch (err) {
      log.error('[auth] keyAuth decryptMsg error', err.message)
      throw new Error(SYNC_CODE.authFailed)
    }
    if (msg != SYNC_CODE.helloMsg) return Promise.reject(new Error(SYNC_CODE.authFailed))
  })
}