crypto.createSign()은 매개변수에 전달된 알고리즘을 사용하는 기호 객체를 생성하고 반환합니다. 사용 가능한 모든 다이제스트 알고리즘의 이름을 가져오기 위해 crypto.getHashes()를 사용할 수 있습니다. 일부 경우에만 다이제스트 알고리즘 대신 'RHA-SHA256'과 같은 서명 알고리즘의 이름을 사용하여 Sign 인스턴스를 생성할 수 있습니다.
구문
crypto.createSign(algorithm, [options])
매개변수
위의 매개변수는 다음과 같이 설명됩니다 -
-
알고리즘 – 기호 객체/인스턴스를 생성할 때 사용할 알고리즘 이름을 입력 받습니다.
-
옵션 – 이것은 스트림 동작을 제어하는 데 사용할 수 있는 선택적 매개변수입니다.
예시
이름이 createSign.js인 파일을 만들고 아래 코드 스니펫을 복사합니다. 파일을 생성한 후 다음 명령을 사용하여 아래 예와 같이 이 코드를 실행하십시오 -
node createSign.js
createSign.js
// Node.js program to demonstrate the use of createSign() method
// Importing the crypto module
const crypto = require('crypto');
// Creating sign object with the input algorithm
const sign = crypto.createSign('SHA256');
// Returning the sign object
console.log(sign); 출력
C:\home\node>> node createSign.js
Sign {
_handle: {},
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: true,
autoDestroy: false,
bufferedRequestCount: 0,
corkedRequestsFree:
{ next: null,
entry: null,
finish: [Function: bound onCorkedFinish] } },
writable: true,
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined } 예시
예를 하나 더 살펴보겠습니다.
// Node.js program to demonstrate the use of createSign() method
// Importing the crypto module
const crypto = require('crypto');
// Creating sign object with the input algorithm
const sign = crypto.createSign('SHA256');
// Returning the sign object
console.log(sign.write('Welcome to Tutorials Point')); 출력
C:\home\node>> node createSign.js true