-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
incluindo estrutura de pastas para adotar o chacha e o salsa
- Loading branch information
1 parent
543e50b
commit cfdd960
Showing
22 changed files
with
82 additions
and
20 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { EncryptedURIAlgorithm, EncryptedURIDecrypter, EncryptedURIEncrypter, TEncryptedURI, TEncryptedURIResultset } from '@encrypted-uri/core'; | ||
import { chacha8 } from '@noble/ciphers/chacha'; | ||
import { TNumberOnceParams, getNumberOnce } from '../number-once'; | ||
import { hexToBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils'; | ||
import { kdf } from '../kdf'; | ||
import { OpenSSLSerializer } from '../openssl-serializer'; | ||
import { base64 } from '@scure/base'; | ||
import { getSalt } from '../salt'; | ||
|
||
class EncryptedURIAESSIVDecrypter extends EncryptedURIDecrypter<TNumberOnceParams> { | ||
constructor( | ||
decoded: TEncryptedURI<TNumberOnceParams>, | ||
password: string | ||
) { | ||
super(decoded, password); | ||
} | ||
|
||
async decrypt(): Promise<string> { | ||
const nonce = getNumberOnce(this.decoded); | ||
const cipher = base64.decode(this.decoded.cipher); | ||
const params = getSalt(cipher, this.decoded?.params); | ||
const derivatedKey = kdf(this.password, params.salt, this.decoded); | ||
const result = await chacha8(derivatedKey, hexToBytes(nonce)) | ||
.decrypt(params.cipher); | ||
|
||
return bytesToUtf8(result); | ||
} | ||
} | ||
|
||
@EncryptedURIAlgorithm({ | ||
algorithm: 'aes/siv', | ||
decrypter: EncryptedURIAESSIVDecrypter | ||
}) | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
class EncryptedURIAESSIVEncrypter extends EncryptedURIEncrypter<TNumberOnceParams> { | ||
|
||
constructor( | ||
params: TEncryptedURIResultset<TNumberOnceParams> | ||
) { | ||
super(params); | ||
} | ||
|
||
async encrypt(): Promise<TEncryptedURI<TNumberOnceParams>> { | ||
const numberOnceHex = getNumberOnce(this.params); | ||
const nonce = hexToBytes(numberOnceHex); | ||
const content = utf8ToBytes(this.params.content); | ||
const saltLength = 8; | ||
const salt = randomBytes(saltLength); | ||
const derivatedKey = kdf(this.params.password, salt, this.params); | ||
const cipher = await chacha8(derivatedKey, nonce, content); | ||
|
||
return Promise.resolve({ | ||
cipher: base64.encode(OpenSSLSerializer.encode(cipher, salt)), | ||
params: { no: numberOnceHex } | ||
}); | ||
} | ||
} | ||
|
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { ripemd160 } from '@noble/hashes/ripemd160'; | ||
import { HashSupport } from './hash-support'; | ||
|
||
HashSupport.addSupport('ripemd160', ripemd160); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
Empty file.
Empty file.
File renamed without changes.