MCPcopy Create free account
hub / github.com/cryptii/cryptii / performTranslate

Method performTranslate

src/Encoder/BlockCipher.js:175–193  ·  view source on GitHub ↗

* Performs encode or decode on given content. * @protected * @param {Chain} content * @param {boolean} isEncode True for encoding, false for decoding * @return {number[]|string|Uint8Array|Chain|Promise} Resulting content

(content, isEncode)

Source from the content-addressed store, hash-verified

173 * @return {number[]|string|Uint8Array|Chain|Promise} Resulting content
174 */
175 async performTranslate (content, isEncode) {
176 const message = content.getBytes()
177 const { algorithm, mode, key, padding, iv } = this.getSettingValues()
178
179 try {
180 // Try to encrypt or decrypt
181 return await this.createCipher(
182 algorithm, mode, key, iv, padding, isEncode, message)
183 } catch (err) {
184 // Catch invalid input errors
185 if (!isEncode) {
186 throw new InvalidInputError(
187 `${algorithm} decryption failed, ` +
188 'this may be due to malformed content')
189 } else {
190 throw new InvalidInputError(`${algorithm} encryption failed`)
191 }
192 }
193 }
194
195 /**
196 * Creates message cipher using given algorithm.

Callers

nothing calls this directly

Calls 3

createCipherMethod · 0.95
getBytesMethod · 0.80
getSettingValuesMethod · 0.80

Tested by

no test coverage detected