D
Deno

help

When I use crypto in this code, it returns 'Unknown cipher.'

Nnew_hope9/24/2023
const secret ="1111111111111111111"; let encryptedText='test'; const decipher = crypto.createDecipheriv('aes-256-cbc', secret, secret.slice(0, 16)); decipher.setAutoPadding(true); let decrypted = decipher.update(encryptedText.slice(16), 'base64', 'utf8'); decrypted += decipher.final('utf8'); How to fix it?
DAHDeno AI Helper9/24/2023
I'm sorry, but the code you provided seems to be using Node.js's crypto module, which is not available in Deno. In Deno, we use the Web Cryptography API for cryptographic operations. The documentation does not provide a direct equivalent for your code, but it does provide examples of how to use the Web Cryptography API for various cryptographic operations such as hashing, encoding, and decoding. Here's an example of how you might encode and decode a string using the Web Cryptography API in Deno:
import * as base64 from "https://deno.land/std@0.194.0/encoding/base64.ts";

const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();

// Encoding
const arrayBuffer = textEncoder.encode("somestringtoencode");
const base64Encoded = base64.encode(arrayBuffer);
console.log(base64Encoded);

// Decoding
const base64Decoded = base64.decode(base64Encoded);
console.log(textDecoder.decode(base64Decoded));
import * as base64 from "https://deno.land/std@0.194.0/encoding/base64.ts";

const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();

// Encoding
const arrayBuffer = textEncoder.encode("somestringtoencode");
const base64Encoded = base64.encode(arrayBuffer);
console.log(base64Encoded);

// Decoding
const base64Decoded = base64.decode(base64Encoded);
console.log(textDecoder.decode(base64Decoded));
Please note that this is a simple example and does not include any encryption or decryption. The Web Cryptography API in Deno does support more advanced operations like encryption and decryption, but the documentation does not provide a clear example of how to use these features. 🦕
Ddivy9/24/2023
hey, aes-256-cbc is not implemented in node:crypto. can you open an issue on github?

Looking for more? Join the community!