deno.land / std@0.157.0 / node / _crypto / crypto_browserify / browserify_aes / modes / cfb.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.// Copyright 2014-2017 browserify-aes contributors. All rights reserved. MIT license.// Copyright 2013 Maxwell Krohn. All rights reserved. MIT license.// Copyright 2009-2013 Jeff Mott. All rights reserved. MIT license.
import { xor } from "../xor.ts";import { Buffer } from "../../../../buffer.ts";
function encryptStart(self, data, decrypt) { const len = data.length; const out = xor(data, self._cache); self._cache = self._cache.slice(len); self._prev = Buffer.concat([self._prev, decrypt ? data : out]); return out;}
export const encrypt = function (self, data, decrypt) { let out = Buffer.allocUnsafe(0); let len;
while (data.length) { if (self._cache.length === 0) { self._cache = self._cipher.encryptBlock(self._prev); self._prev = Buffer.allocUnsafe(0); }
if (self._cache.length <= data.length) { len = self._cache.length; out = Buffer.concat([ out, encryptStart(self, data.slice(0, len), decrypt), ]); data = data.slice(len); } else { out = Buffer.concat([out, encryptStart(self, data, decrypt)]); break; } }
return out;};
std

Version Info

Tagged at
2 years ago