mirror of
https://github.com/cupcakearmy/occulto.git
synced 2025-09-06 08:50:44 +00:00
add generate key
This commit is contained in:
@@ -29,7 +29,8 @@ export enum Modes {
|
||||
export class AES {
|
||||
static Modes = Modes
|
||||
|
||||
private static delimiter = '--' // delimiter with a character that is not allowed in base64 or hex
|
||||
// delimiter with a character that is not allowed in base64 or hex
|
||||
private static delimiter = '--'
|
||||
private static delimiterEasy = '---'
|
||||
|
||||
private static InvalidCiphertext = new Error('Invalid ciphertext')
|
||||
@@ -141,4 +142,18 @@ export class AES {
|
||||
const decrypted = await this.decrypt(data, keyDerived)
|
||||
return Bytes.decode(decrypted)
|
||||
}
|
||||
|
||||
static async generateKey(): Promise<TypedArray> {
|
||||
const c = await getCrypto()
|
||||
const key = await c.subtle.generateKey(
|
||||
{
|
||||
name: 'AES-GCM',
|
||||
length: 256,
|
||||
},
|
||||
true,
|
||||
['encrypt', 'decrypt']
|
||||
)
|
||||
const buffer = await c.subtle.exportKey('raw', key)
|
||||
return new Uint8Array(buffer)
|
||||
}
|
||||
}
|
||||
|
@@ -3,4 +3,4 @@ export * from './crypto/encoding.js'
|
||||
export * from './crypto/hash.js'
|
||||
export * from './crypto/random.js'
|
||||
export * from './crypto/rsa.js'
|
||||
export * from './utils/base.js'
|
||||
export { TypedArray } from './utils/base.js'
|
||||
|
Reference in New Issue
Block a user