Skip to content

Commit

Permalink
updating examples readme
Browse files Browse the repository at this point in the history
  • Loading branch information
WingZer0o committed May 12, 2024
1 parent aa5a522 commit 39b422c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
99 changes: 99 additions & 0 deletions docs/EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,105 @@ const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
```

### Asymmetric
-RSA
```typescript
const rsaWrapper: RSAWrapper = new RSAWrapper();
const keys: RsaKeyPairResult = rsaWrapper.generateKeys(4096);
const tohashed: string = "This is my array to encrypt";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const ciphertext = rsaWrapper.encrypt(keys.publicKey, tohashBytes);
const plaintext = rsaWrapper.decrypt(keys.privateKey, ciphertext);
```


### Digital Signature
-ED25519 SHA
```typescript
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
const toHash: string = "This is my array to encrypt";
const encoder = new TextEncoder();
const toHashBytes: Array<number> = Array.from(encoder.encode(toHash));
const dsResult = shaDsWrapper.createED25519(toHashBytes);
const verify = shaDsWrapper.verifyED25519(dsResult.publicKey, toHashBytes, dsResult.signature);
```

-RSA SHA
```typescript
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
const tohashed: string = "This is my array to encrypt";
const notOriginal: string = "This is not a fun time";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
const dsResult: RSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
```


### Hashers
-SHA3 512
```typescript
const wrapper = new SHAWrapper();
const tohashed: string = "This is my array to hash";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const hashed = wrapper.hash512(tohashBytes);
```

-SHA3 256
```typescript
const wrapper = new SHAWrapper();
const tohashed: string = "This is my array to hash";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const hashed = wrapper.hash256(tohashBytes);
```

### Hybrid Encryption
-AES/RSA Encryption
```typescript
const hybridWrapper = new HybridEncryptionWrapper();
let initalizer = new AESRSAHybridInitializer(128, 4096);
const tohashed: string = "This is my encrypt text for rsa hybrid";
const encoder = new TextEncoder();
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
let result: AesRsaHybridEncryptResult = hybridWrapper.encrypt(toEncrypt, initalizer);
let plaintext: Array<number> = hybridWrapper.decrypt(initalizer.rsaKeyPair.privateKey, result);
```

### Key Exchange
-X25519
```typescript
const wrapper = new X25519Wrapper();
const alice = wrapper.generateSecretAndPublicKey();
const bob = wrapper.generateSecretAndPublicKey();

const alice_shared_secret = wrapper.generateSharedSecret(
alice.secretKey,
bob.publicKey,
);
const bob_shared_secret = wrapper.generateSharedSecret(
bob.secretKey,
alice.publicKey,
);

var result = areEqual(alice_shared_secret, bob_shared_secret);
```

### Sponges
-Ascon 128
```typescript
const wrapper: AsconWrapper = new AsconWrapper();
const key: Array<number> = wrapper.ascon128Key();
const nonce: Array<number> = wrapper.ascon128Nonce();
const tohashed: string = "This is my array to encrypt";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const ciphertext = wrapper.ascon128Encrypt(key, nonce, tohashBytes);
const plaintext = wrapper.ascon128Decrypt(key, nonce, ciphertext);
```

### Passwords
- BCrypt
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"name": "cas-typescript-sdk",
"version": "1.0.20",
"version": "1.0.21",
"description": "",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down

0 comments on commit 39b422c

Please sign in to comment.