Node.jsのDecipher.final()メソッド
decipher.final()は、decipherオブジェクトの値を含むバッファまたは文字列を返すために使用されます。これは、暗号モジュール内のクラスCipherによって提供される組み込みメソッドの1つです。 decipher.finalメソッドが呼び出されると、decipherメソッドを使用してデータを復号化することはできません。 cipher.finalメソッドを複数回呼び出すと、エラーがスローされます。
構文
decipher.final([outputEncoding])
パラメータ
上記のパラメータは以下のように記述されます-
-
outputEncoding –出力エンコーディングをパラメーターとして受け取ります。このパラメータの入力タイプは文字列です。可能な入力値は、hex、base64などです。
例
decipherFinal.jsという名前のファイルを作成し、以下のコードスニペットをコピーします。ファイルを作成したら、次のコマンドを使用して、以下の例に示すようにこのコードを実行します-
node decipherFinal.js
decodeFinal.js
// Example to demonstrate the use of cipher.final() method
// Importing the crypto module
const crypto = require('crypto');
// Initialising the AES algorithm
const algorithm = 'aes-192-cbc';
// Initialising the password used for generating key
const password = '12345678123456789';
// Retrieving key for the decipher object
const key = crypto.scryptSync(password, 'old data', 24);
// Initializing the static iv
const iv = Buffer.alloc(16, 0);
const decipher = crypto.createDecipheriv(algorithm, key, iv);
// Initializing the cipher object to get cipher
const encrypted1 =
'a05e87569f3f04234812ae997da5684944c32b8776fae676b4abe9074b31cd2a';
// const encrypted2 = '8d11772fce59f08e7558db5bf17b3112';
let decryptedValue1 = decipher.update(encrypted1, 'hex', 'utf8');
// let decryptedValue1 = decipher.update(encrypted1, 'hex', 'utf8');
decryptedValue1 += decipher.final('utf8');
// Printing the result...
console.log("Decrypted value -- " + decryptedValue1);
// console.log("Base64 String:- " + base64Value) 出力
C:\home\node>> node decipherFinal.js Decrypted value -- Welcome to tutorials point
例
もう1つの例を見てみましょう。
// Example to demonstrate the use of cipher.final() method
// Importing the crypto module
const crypto = require('crypto');
// Initialising the AES algorithm
const algorithm = 'aes-192-cbc';
// Initialising the password used for generating key
const password = '12345678123456789';
// Retrieving key for the decipher object
const key = crypto.scryptSync(password, 'old data', 24);
// Initializing the static iv
const iv = Buffer.alloc(16, 0);
const decipher = crypto.createDecipheriv(algorithm, key, iv);
// Initializing the cipher object to get cipher
const encrypted =
'a05e87569f3f04234812ae997da5684944c32b8776fae676b4abe9074b31cd2a';
// const encrypted2 = '8d11772fce59f08e7558db5bf17b3112';
var buf = [];
// Updating the decopher data
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
// Pushinf the data into buffer after decryption
buf.push(decrypted);
buf.push(decipher.final('utf8'));
// Printing the result
console.log(buf.join(' '));を出力します 出力
C:\home\node>> node decipherFinal.js Welcome to tutor ials point
-
Node.jsのprocess.argv0()メソッド
process.argv0()メソッドは、node.jsアプリケーションの起動時に渡されるargv[0]の元の値の読み取り専用コピーを保存するために使用されます。 構文 process.argv0() パラメータ argv[0]のプリペイドカードの読み取り専用コピーのみを返すため。ユーザーからの入力は必要ありません。 例 argv0.jsという名前のファイルを作成し、以下のコードスニペットをコピーします。ファイルを作成したら、次のコマンドを使用して、以下の例に示すようにこのコードを実行します- node argv0.js argv0.js // Node.js program to
-
Node.jsのprocess.argv()メソッド
process.argv()メソッドは、Node.jsプロセスの起動時に渡されたすべてのコマンドライン引数を返すために使用されます。最初の要素には、常にprocess.execPathと同じ値が含まれます。 構文 process.argv() パラメータ node.jsプロセスの前に渡されたすべてのコマンドライン引数を返すため。ユーザーからの入力は必要ありません。 例 argv.jsという名前のファイルを作成し、以下のコードスニペットをコピーします。ファイルを作成したら、次のコマンドを使用して、以下の例に示すようにこのコードを実行します- node argv.js argv.js