but not normal encryption from SHA256 there other set up before get it, so need to apply this function into openbullet some one can make this on openbullet as function please
* Converts a string to a hash using the SHA-256 algorithm
*
* @param text Text to be hashed
* @return hash string
*/
public async hash(text: string): Promise<string> {
try {
const hash = await this.createHashBuffer(text);
return Promise.resolve(this.createHexFromBuffer(hash));
} catch (error) {
return Promise.reject(error);
}
}
/**
* Creates an array buffer using the web crypto utility
*
* @param text text to be hashed
*/
private createHashBuffer(text: string): PromiseLike<ArrayBuffer> {
return new Promise(async (resolve, reject) => {
try {
const buffer = this.textEncoder(text);
// It's a modern browser
if (!window['msCrypto']) {
const hash = await crypto.subtle.digest('SHA-256', buffer);
resolve(hash);
}
For anyone interested this was the solution, im sure its possible without using a script block but I couldn’t figure it out.
BLOCK:ConstantString
value = @input.PASSWORD
=> VAR @pwd
ENDBLOCK
BLOCK:Script
INTERPRETER:NodeJS
INPUT pwd
BEGIN SCRIPT
const crypto = require('crypto');
function hash256(input) {
const hash = crypto.createHash('sha256').update(Buffer.from(input, 'utf8')).digest('hex');
let output = '';
for (let i = 0; i < hash.length; i += 2) {
const value = hash.substr(i, 2);
if (value.startsWith('0')) {
output += value.replace('0', '');
} else {
output += value;
}
}
return output;
}
const password_hash = hash256(pwd);
END SCRIPT
OUTPUT String @password_hash
ENDBLOCK
Sha256 hash for ‘test’:
site generated: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2bb822cd15d6c15b0f0a8
normal sha256 hash: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
Since the site does not do it intentionally I assume its because of the package they use:
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class HashService {
/**
* Converts a string to a hash using the SHA-256 algorithm
*
* @param text Text to be hashed
* @return hash string
*/
public async hash(text: string): Promise<string> {
try {
const hash = await this.createHashBuffer(text);
return Promise.resolve(this.createHexFromBuffer(hash));
} catch (error) {
return Promise.reject(error);
}
}
/**
* Creates an array buffer using the web crypto utility
*
* @param text text to be hashed
*/
private createHashBuffer(text: string): PromiseLike<ArrayBuffer> {
return new Promise(async (resolve, reject) => {
try {
const buffer = this.textEncoder(text);
// It's a modern browser
if (!window['msCrypto']) {
const hash = await crypto.subtle.digest('SHA-256', buffer);
resolve(hash);
}
// IE Polyfill
const res = window['msCrypto'].subtle.digest('SHA-256', buffer);
res.oncomplete = (buff) => {
resolve(buff.target.result);
};
} catch (error) {
reject(error);
}
});
}
/**
* Encodes a text to Unit8Array
* if the TextEncoder does not exist (IE11) executes the polyfill
*
* @param text Text to encode
*/
private textEncoder(text: string): Uint8Array {
if (window['TextEncoder']) {
return new TextEncoder().encode(text);
}
// IE11 Polyfill
const utf8 = unescape(encodeURIComponent(text));
const result = new Uint8Array(utf8.length);
for (let i = 0; i < utf8.length; i++) {
result[i] = utf8.charCodeAt(i);
}
return result;
}
/**
* Converts an string array buffer to a hexadecimal string
*
* @param buffer Array buffer from a string
*/
private createHexFromBuffer(buffer: ArrayBuffer): string {
return Array.prototype.map
.call(new Uint8Array(buffer), (byte) => byte.toString(16))
.join('');
}
}