Skip to content
forked from cyph/rsasign.js

JavaScript wrapper native RSASSA-PKCS1-v1_5.

License

Notifications You must be signed in to change notification settings

hfbhfb/rsasign.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rsasign.js

Overview

RSASSA-PKCS1-v1_5 with key length 2048 and hash function SHA-256 wrapped for usage in JavaScript.

The platform native RSA implementation (via SubtleCrypto or the Node.js Crypto API) is preferred where available. Otherwise, the OpenSSL implementation compiled to pure JavaScript with Emscripten is used as a fallback.

Example Usage

(async () => {
	const keyPair /*: {privateKey: Uint8Array; publicKey: Uint8Array} */ =
		await rsaSign.keyPair()
	;

	const message /*: Uint8Array */ =
		new Uint8Array([104, 101, 108, 108, 111, 0]) // "hello"
	;

	/* Combined signatures */

	const signed /*: Uint8Array */ =
		await rsaSign.sign(message, keyPair.privateKey)
	;

	const verified /*: Uint8Array */ =
		await rsaSign.open(signed, keyPair.publicKey) // same as message
	;

	/* Detached signatures */
	
	const signature /*: Uint8Array */ =
		await rsaSign.signDetached(message, keyPair.privateKey)
	;

	const isValid /*: boolean */ =
		await rsaSign.verifyDetached(signature, message, keyPair.publicKey) // true
	;

	console.log(keyPair);
	console.log(message);
	console.log(signed);
	console.log(verified);
	console.log(signature);
	console.log(isValid);
})();

About

JavaScript wrapper native RSASSA-PKCS1-v1_5.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 56.4%
  • Makefile 26.0%
  • C 17.6%