All Projects → adria0 → SolRsaVerify

adria0 / SolRsaVerify

Licence: GPL-3.0 license
Solidity RSA Sha256 Pkcs1 Verification

Programming Languages

javascript
184084 projects - #8 most used programming language
solidity
1140 projects

Projects that are alternatives of or similar to SolRsaVerify

Jsrsasign
The 'jsrsasign' (RSA-Sign JavaScript Library) is an opensource free cryptography library supporting RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp, CAdES JSON Web Signature/Token in pure JavaScript.
Stars: ✭ 2,760 (+6033.33%)
Mutual labels:  signature, rsa
Easyrsa
Simple and Secure Wrapper for phpseclib
Stars: ✭ 183 (+306.67%)
Mutual labels:  signature, rsa
signature
HMAC and RSA signature for Laravel and Lumen
Stars: ✭ 26 (-42.22%)
Mutual labels:  signature, rsa
Auth Jwt
A demo to learn JWT by reverse engineering
Stars: ✭ 208 (+362.22%)
Mutual labels:  signature, rsa
bleichenbacher
Bleichenbachers "Million message attack" on RSA in Python
Stars: ✭ 24 (-46.67%)
Mutual labels:  rsa, pkcs1
prune-horst
Signature scheme submitted to NIST's Post-Quantum Cryptography Project
Stars: ✭ 23 (-48.89%)
Mutual labels:  signature
SnortRules
This is an open source Snort rules repository
Stars: ✭ 18 (-60%)
Mutual labels:  signature
RSA-ATTACK
RSA加密应用常见缺陷的原理与实践
Stars: ✭ 155 (+244.44%)
Mutual labels:  rsa
goosig
Anonymous RSA signatures
Stars: ✭ 65 (+44.44%)
Mutual labels:  rsa
SignatureView
【Android View】:好用的Android电子签名板,能保存所签名的图片
Stars: ✭ 89 (+97.78%)
Mutual labels:  signature
adfsmfa
MFA for ADFS 2022/2019/2016/2012r2
Stars: ✭ 86 (+91.11%)
Mutual labels:  rsa
pgpainless
Simple to use OpenPGP API based on Bouncy Castle
Stars: ✭ 73 (+62.22%)
Mutual labels:  signature
webcrypto
A WebCrypto Polyfill for NodeJS
Stars: ✭ 111 (+146.67%)
Mutual labels:  rsa
blind-signatures
Chaum's Blind Signatures
Stars: ✭ 24 (-46.67%)
Mutual labels:  signature
react-native-signview
Signature view for react native(Android + IOS)
Stars: ✭ 15 (-66.67%)
Mutual labels:  signature
common-secure
提供一些加密算法java代码封装 包括 RSA/AES/DES/3DES/MD5/SHA/HmacSHA256
Stars: ✭ 37 (-17.78%)
Mutual labels:  rsa
smooth-signature
H5带笔锋手写签名,支持PC端和移动端,任何前端框架均可使用
Stars: ✭ 474 (+953.33%)
Mutual labels:  signature
pyseto
A Python implementation of PASETO and PASERK.
Stars: ✭ 21 (-53.33%)
Mutual labels:  signature
littleca
littleca是一个基于BC的小型ca库,支持ecc,rsa,dsa,sm2的证书签发,加密解密,签名验签操作,支持国密加解密,证书签发
Stars: ✭ 44 (-2.22%)
Mutual labels:  rsa
gravity-sphincs
Signature scheme submitted to NIST's Post-Quantum Cryptography Project
Stars: ✭ 67 (+48.89%)
Mutual labels:  signature

SolRsaVerify

Build Status License: GPL v3

Verification of RSA Sha256 Pkcs1.5 Signatures

This kind of signatures (with PSS) are standard in CryptoAPIs when generating RSA signatures.

Checked results with FIPS test vectors https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/dss/186-2rsatestvectors.zip file SigVer15_186-3.rsp

Usage

First you'll need an RSA private key. You can generate one using the openssl cli:

$ openssl genrsa -out private.pem 1024
Generating RSA private key, 1024 bit long modulus
................................................++++++
..................................................++++++
e is 65537 (0x10001)

Next lets sign a message:

$ echo -n "hello world" | openssl dgst -sha256 -sign private.pem -out | xxd -p | tr -d \\n
00d5380ea463dcb195e887bd900c2e25098401378d6da2e97e56ef1b984e6a67959f7adc662727e0c1e3ea3580caecba6a69925eec3704413e2192b0ff40f4711d424e4e1ecc6128534a2527c04bb1576c4582a589559a8ff9ad2bfd5f09f856dfefd90cd0464dee63f7b10d0b5ef69c389bc4ef4a9d35254fcad5ad246cc6a3%

We pass the string "hello world" to openssl to sign it and then to xxd to convert from binary to hex and finally to tr to truncate newlines.

Now let's extract the public key from the private key:

$ openssl rsa -in private.pem -outform der -pubout -out public.pem
writing RSA key

And finally we need to extract n (the modulus) from the public key:

$  openssl asn1parse -inform TXT -i -in public.pem -strparse 18
0:d=0  hl=3 l= 137 cons: SEQUENCE
3:d=1  hl=3 l= 129 prim:  INTEGER           :B793F2F926170FAD768F8B1A5769A2243B4CDCAC4780194F59B39E1A2ABC3BB8EA42DB495D17BEC7F7072A11ED4FA510E75A7886A5DB6F71B7AFCA0090CA079889D18AF0669829ED29A8E21D0C09BD19CAAF2FE2CC8121BFC5687AC6698E3022F468A481426486CAD263BE1A119491E034A6E1AB78F19C066D4145A50F9ECFF7
135:d=1  hl=2 l=   3 prim:  INTEGER           :010001

Now we can call SolRsaVerify.pkcs1Sha256VerifyRaw and verify the signature:

const message = web3.utils.asciiToHex("hello world");
const modulus = "0xB793F2F926170FAD768F8B1A5769A2243B4CDCAC4780194F59B39E1A2ABC3BB8EA42DB495D17BEC7F7072A11ED4FA510E75A7886A5DB6F71B7AFCA0090CA079889D18AF0669829ED29A8E21D0C09BD19CAAF2FE2CC8121BFC5687AC6698E3022F468A481426486CAD263BE1A119491E034A6E1AB78F19C066D4145A50F9ECFF7";
const exponent= "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010001";
const signature = "0x57a0d6a185924d9d579b3ab319fe512331cb0bc6ef2da7d5285cbd06844f5c44662cae2e41ee5020893d6690e34b50a369a78250ae81ba6d708560535ef7cff0299f2ba070b096a9a76e84cf9c902b5e367b341ee166f5fc325dd08a3d971d96d528937f617a1eaf2250c56c4edca80c65970d54fe2492a19468bd32166b3c32";

const contract = await SolRsaVerify.new();
const result = await contract.pkcs1Sha256VerifyRaw(message, signature, exponent, modulus);
if (result == 0) {
  console.log("Signature is valid");
} else {
  console.log("Signature is invalid");
}

(Note: don't forget to prefix the hex values with 0x)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].