mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-28 12:37:00 +00:00
companion,website: make encryption shorter + enable onedrive on website example
This commit is contained in:
parent
78003c2f5b
commit
61edba36b3
3 changed files with 9 additions and 14 deletions
|
|
@ -123,11 +123,11 @@ function createIv () {
|
|||
}
|
||||
|
||||
function urlEncode (unencoded) {
|
||||
return unencoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ',')
|
||||
return unencoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '~')
|
||||
}
|
||||
|
||||
function urlDecode (encoded) {
|
||||
encoded = encoded.replace(/-/g, '+').replace(/_/g, '/').replace(/,/g, '=')
|
||||
encoded = encoded.replace(/-/g, '+').replace(/_/g, '/').replace(/~/g, '=')
|
||||
return encoded
|
||||
}
|
||||
|
||||
|
|
@ -141,10 +141,10 @@ function urlDecode (encoded) {
|
|||
module.exports.encrypt = (input, secret) => {
|
||||
const iv = createIv()
|
||||
const cipher = crypto.createCipheriv('aes256', createSecret(secret), iv)
|
||||
let encrypted = iv.toString('hex')
|
||||
encrypted += urlEncode(cipher.update(input, 'utf8', 'base64'))
|
||||
encrypted += urlEncode(cipher.final('base64'))
|
||||
return encrypted
|
||||
let encrypted = cipher.update(input, 'utf8', 'base64')
|
||||
encrypted += cipher.final('base64')
|
||||
// add iv to encrypted string to use for decryption
|
||||
return iv.toString('hex') + urlEncode(encrypted)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -161,8 +161,9 @@ module.exports.decrypt = (encrypted, secret) => {
|
|||
}
|
||||
|
||||
const iv = Buffer.from(encrypted.slice(0, 32), 'hex')
|
||||
const encryptionWithoutIv = encrypted.slice(32)
|
||||
const decipher = crypto.createDecipheriv('aes256', createSecret(secret), iv)
|
||||
let decrypted = decipher.update(urlDecode(encrypted.slice(32)), 'base64', 'utf8')
|
||||
let decrypted = decipher.update(urlDecode(encryptionWithoutIv), 'base64', 'utf8')
|
||||
decrypted += decipher.final('utf8')
|
||||
return decrypted
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ describe('test authentication', () => {
|
|||
.expect(200)
|
||||
.expect((res) => {
|
||||
const authToken = res.header['set-cookie'][0].split(';')[0].split('uppyAuthToken--google=')[1]
|
||||
expect(decodeURIComponent(authToken)).toEqual(token)
|
||||
expect(authToken).toEqual(token)
|
||||
const body = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
|
|
|||
|
|
@ -108,11 +108,5 @@
|
|||
facebookCheckbox.style.display = 'inline-block'
|
||||
}
|
||||
|
||||
const onedriveCheckbox = document.getElementById('onedrive-checkbox')
|
||||
onedriveCheckbox.style.display = 'none'
|
||||
if (document.location.hash === '#enable-onedrive') {
|
||||
onedriveCheckbox.style.display = 'inline-block'
|
||||
}
|
||||
|
||||
toggleModalBtn()
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue