Skip to content

Instantly share code, notes, and snippets.

@Wind010
Created August 26, 2024 20:23
Show Gist options
  • Save Wind010/79a4f46d3650ade333dc17b100c9919d to your computer and use it in GitHub Desktop.
Save Wind010/79a4f46d3650ade333dc17b100c9919d to your computer and use it in GitHub Desktop.
Just some easier code for Duplicati Login with known NONCE and Salted Password.
const base64Decode = str => Uint8Array.from(atob(str), c => c.charCodeAt(0));
const base64Encode = bytes => btoa(String.fromCharCode(...new Uint8Array(bytes)));
const generatePassword = async (nounce, saltedPassword) => {
const bytesNounce = base64Decode(nounce);
const bytesSaltedPassword = base64Decode(saltedPassword);
const concatenatedBytes = new Uint8Array([...bytesNounce, ...bytesSaltedPassword]);
const hash = await crypto.subtle.digest('SHA-256', concatenatedBytes);
return base64Encode(hash);
};
const urlEncode = str => encodeURIComponent(str).replace(/%20/g, '+');
const nounce = 'NONCE';
const saltedPassword = 'SALTED_PASSWORD';
generatePassword(nounce, saltedPassword).then(noncedPassword => {
console.log(noncedPassword, urlEncode(noncedPassword));
});
import hashlib
import base64
from urllib.parse import unquote, quote_plus
def generate_password(nounce: str, salted_password: str):
bytes_nounce, bytes_salted_password = base64.b64decode(unquote(nounce)), base64.b64decode(salted_password)
hex_nounce, hex_salted_password = bytes_nounce.hex(), bytes_salted_password.hex()
hex_concatenated = hex_nounce + hex_salted_password
concatenated_bytes = bytes.fromhex(hex_concatenated)
sha256_hash = hashlib.sha256(concatenated_bytes).digest()
return base64.b64encode(sha256_hash).decode('utf-8')
nonced_password = generate_password('NONCE', 'SALTED_PASSWORD')
url_encoded_nonced_password = quote_plus(nonced_password)
print(nonced_password, url_encoded_nonced_password)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment