Skip to content

Commit

Permalink
feat: refactor app crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
zdm committed Dec 25, 2024
1 parent 062a299 commit 58b2c42
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/app/components/crypto/crypto/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,20 @@ export default class CryptoStorage {

// private
#parseKey ( key ) {
if ( Buffer.isBuffer( key ) || typeof key === "string" ) {
key = crypto.createSecretKey( key, "base64url" );
}
try {
if ( Buffer.isBuffer( key ) || typeof key === "string" ) {
key = crypto.createSecretKey( key, "base64url" );
}

if ( key.type !== "secret" || key.symmetricKeySize !== 32 ) {
return result( [ 400, `AES key 256 bits length is required` ] );
}
if ( key.type !== "secret" || key.symmetricKeySize !== 32 ) {
return result( [ 400, `AES key 256 bits length is required` ] );
}

return result( 200, key );
return result( 200, key );
}
catch ( e ) {
return result.catch( e );
}
}

async #generateKey () {
Expand Down

0 comments on commit 58b2c42

Please sign in to comment.