expo-crypto-universal-web
Version:
Web implementation of expo-crypto-universal
75 lines (44 loc) • 2.01 kB
Markdown
Web implementation of expo-crypto-universal, providing cryptographic operations using the Web Crypto API.
- Random bytes generation
- SHA-256, SHA-384, and SHA-512 hashing
- SHA-2 hashing with configurable bit length
```bash
npm install expo-crypto-universal-web
```
```typescript
import { webCryptoModule } from 'expo-crypto-universal-web';
// Generate random bytes
const randomBytes = webCryptoModule.getRandomBytes(32);
// Fill array with random values
const filledArray = webCryptoModule.getRandomValues(new Uint8Array(32));
// Hash data with SHA-256
const data = new Uint8Array([1, 2, 3, 4]);
const hash256 = await webCryptoModule.sha256Async(data);
// Hash data with SHA-384
const hash384 = await webCryptoModule.sha384Async(data);
// Hash data with SHA-512
const hash512 = await webCryptoModule.sha512Async(data);
// Hash data with SHA-2 (configurable bit length)
const hash = await webCryptoModule.sha2Async(256, data); // 256, 384, or 512 bits
```
Generates cryptographically secure random bytes of the specified size.
Fills the provided Uint8Array with cryptographically secure random values.
Computes the SHA-256 hash of the input data.
Computes the SHA-384 hash of the input data.
Computes the SHA-512 hash of the input data.
Computes the SHA-2 hash of the input data with the specified bit length (256, 384, or 512).
## Security
This implementation uses the Web Crypto API for all cryptographic operations, ensuring high security standards.
## License
MIT