library-ts/browser/random/CryptoTool.ts

35 lines
646 B
TypeScript

import { JSRandomEngine } from "./JSRandomEngine";
export class CryptoTool
{
static randomUUID():string
{
if ( window.location.protocol !== "https" )
{
let random = JSRandomEngine.$;
let structure = [8,4,4,4,12];
let id = "";
let first = true;
for ( let j = 0; j < structure.length; j++ )
{
if ( first ){ first = false; }
else{ id +="-"; }
let num = structure[ j ];
for ( let i = 0; i < num; i++ )
{
id += random.fromString( "0123456789abcdef" );
}
}
return id;
}
return crypto.randomUUID();
}
}