Node.jsのdecipher.update()メソッド
decipher.update()は、指定されたエンコード形式に従って、受信したデータで復号化を更新するために使用されます。これは、暗号モジュール内のクラスDecipherによって提供される組み込みメソッドの1つです。入力エンコーディングが指定されている場合、データ引数は文字列です。それ以外の場合、データ引数はバッファです
構文
decipher.update(data, [inputEncoding], [outputEncoding])
パラメータ
上記のパラメータは以下のように記述されます-
-
データ –解読コンテンツを更新するために渡される入力としてデータを受け取ります。
-
inputEncoding –入力エンコーディングをパラメーターとして受け取ります。可能な入力値は、hex、base64などです。
-
outputEncoding –出力エンコーディングをパラメーターとして受け取ります。このパラメータの入力タイプは文字列です。可能な入力値は、hex、base64などです。
例
decipherUpdate.jsという名前のファイルを作成し、以下のコードスニペットをコピーします。ファイルを作成したら、次のコマンドを使用して、以下の例に示すようにこのコードを実行します-
node decipherUpdate.js
decodeUpdate.js
// Example to demonstrate the use of decipher.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 decipher object to get decipher
const encrypted = '083bfe1b2f91677e5d00add115be2f1b2e362e190406f5c6b60e86969bf03bff';
// const encrypted2 = '8d11772fce59f08e7558db5bf17b3112';
let decryptedValue = decipher.update(encrypted, 'hex', 'utf8');
// let decryptedValue1 = decipher.update(encrypted1, 'hex', 'utf8');
decryptedValue += decipher.final('utf8');
// Printing the result...
console.log("Decrypted value -- " + decryptedValue);
// console.log("Base64 String:- " + base64Value) 出力
C:\home\node>> node decipherUpdate.js Decrypted value -- Some new text data
例
もう1つの例を見てみましょう。
// Example to demonstrate the use of decipher.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
crypto.scrypt(password, 'salt', 24,
{ N: 512 }, (err, key) => {
if (err) throw err;
// Initializing the static iv
const iv = Buffer.alloc(16, 0);
// Initializing the decipher with algo, key and iv
const decipher = crypto.createDecipheriv(algorithm, key, iv);
const encrypted = '91d6d37e70fbae537715f0a921d15152194435b96ce3973d92fbbc4a82071074';
//Getting the decrypted string value
const decrypted = decipher.update(encrypted, 'hex', 'utf8');
// Printing the result...
console.log("Decrypted value:- " + decrypted);
}); 出力
C:\home\node>> node decipherUpdate.js Decrypted value:- Some new text data
-
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