Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrypt method in Crypt.js fails #11

Open
wperrigo opened this issue Oct 19, 2017 · 3 comments
Open

Decrypt method in Crypt.js fails #11

wperrigo opened this issue Oct 19, 2017 · 3 comments

Comments

@wperrigo
Copy link

I was always getting a failure in the Decrypt method due to character issues. I had to replace one line to get it to work.

This:
let encoded = JSON.parse(this.constructor.base64decode(encodedString));

Became this:
let tempJSON = this.constructor.base64decode(encodedString) let encoded = JSON.parse(tempJSON.substr(0, tempJSON.indexOf('}')+1));

@vadimpronin
Copy link
Owner

Never seen such problem.
Can you show me the code that you use to encode the token?

@wperrigo
Copy link
Author

// SET ENCRYPTION OPTIONS FOR THE JSON TOKENS
const clientOptions = {
    crypt: {
        cypher: 'AES-256-CBC',
        key: 'hidden_super_secret_key'
    },
    connectionDefaultSettings: {
        rdp: {
            'create-drive-path': true,
            'security': 'any',
            'ignore-cert': true,
            'enable-wallpaper': false,
            'create-recording-path': true
        }
    }
}
const encrypt = (value) => {
    const iv = crypto.randomBytes(16)
    const cipher = crypto.createCipheriv(clientOptions.crypt.cypher, clientOptions.crypt.key, iv)
 
    let crypted = cipher.update(JSON.stringify(value), 'utf8', 'base64')
    crypted += cipher.final('base64')
 
    const data = {
        iv: iv.toString('base64'),
        value: crypted
    }
    return new Buffer(JSON.stringify(data)).toString('base64')
}

@wpcwzy
Copy link

wpcwzy commented Mar 4, 2024

I was always getting a failure in the Decrypt method due to character issues. I had to replace one line to get it to work.

This: let encoded = JSON.parse(this.constructor.base64decode(encodedString));

Became this: let tempJSON = this.constructor.base64decode(encodedString) let encoded = JSON.parse(tempJSON.substr(0, tempJSON.indexOf('}')+1));

Thank you very much. This replacement fixes my problem XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants