-
Notifications
You must be signed in to change notification settings - Fork 109
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
How to set a new password using api.call('account.updatePasswordSettings') #287
Comments
import bigInt from 'big-integer';
import {
concatBytes,
bytesToBigInt,
} from '@mtproto/core/src/utils/common/index.js';
import crypto from 'crypto';
export async function getVParams(api, password) {
const getPasswordConf = await api.call('account.getPassword');
const { new_algo = {} } = getPasswordConf;
const {
g, p, salt1, salt2
} = new_algo;
const SH = (data, salt) => {
const hash = crypto.createHash('sha256');
hash.update(concatBytes(salt, data, salt));
return hash.digest();
};
const PH1 = (password, salt1, salt2) => {
const hash1 = SH(SH(password, salt1), salt2);
return hash1;
};
const PH2 = (password, salt1, salt2) => {
const ph1Result = PH1(password, salt1, salt2);
const pbkdf2Result = crypto.pbkdf2Sync(
ph1Result,
salt1,
100000,
32,
'sha256'
);
return SH(pbkdf2Result, salt2);
};
const encoder = new TextEncoder();
const gBigInt = bigInt(g);
const pBigInt = bytesToBigInt(p);
const x = PH2(encoder.encode(password), salt1, salt2);
const xBigInt = bytesToBigInt(x);
const vBigInt = gBigInt.modPow(xBigInt, pBigInt);
console.log('vBigInt:', vBigInt);
const new_password_hash = crypto
.createHash('sha256')
.update(vBigInt.toString())
.digest();
// 将 Buffer 转换为 Uint8Array
const new_password_hash_uint8 = new Uint8Array(new_password_hash.buffer);
console.log('new_password_hash:', new_password_hash);
return {
...getPasswordConf,
new_password_hash: new_password_hash_uint8,
};
} |
{ |
please help me |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://core.telegram.org/constructor/account.passwordInputSetting
Excuse me, the type of new_password_hash for setting a new password is flags.0?bytes, which is converted into JavaScript, how to express it?
The text was updated successfully, but these errors were encountered: