验证Node.js中的文件签名

时间:2017-07-21 08:29:14

标签: node.js pdf digital-signature node-crypto

我有一个用Adobe Reader签名的pdf文件和一些密钥算法,比如1024位RSA。 如何在具有签名文件和公钥的Node.js中验证签名?

我知道有一个原生模块crypto。但我无法理解如何使用它,这是一个来自docs的例子:

@pytest.fixture(scope='function')
def user(db):
    """An user for the tests."""

    user = UserFactory(
        organizations='',
        subordinates=''
    )

    a = MemberOrgsAssocFactory(
        member_id=None,
        org_id=None,
        manager_id=None,
        is_org_admin=True,
        is_default_org=True,
        is_active=True,
        organization=None,
        member=None,
        manager=None
    )
    a.organization = OrganizationFactory(members=[])
    user.organizations.append(a)
    db.session.commit()

    # debugging
    # thisuser = User.get_by_id(user.id)
    # for assoc in thisuser.organizations:
    #    if assoc.is_default_org:
    #        print('The default organization of thisuser is -> {}'.format(assoc.organization.name))

    return user

任何人都可以对此有所了解吗?

UPD     从我在这里找到的是使用它的正确方法:

const verify = crypto.createVerify('RSA-SHA256');
verify.write('some data to sign'); // should I write pdf file byte stream here?
verify.end();

const publicKey = getPublicKeySomehow();
const signature = getSignatureToVerify(); // this is not clear, what is the signature in current context?
console.log(verify.verify(publicKey, signature));

但它会引发下一个错误

const res = verify.verify(fs.readFileSync('cert.cer'), fs.readFileSync('signed_doc.pdf'))

问题:我可以将Error: PEM_read_bio_PUBKEY failed at Error (native) at Verify.verify (crypto.js:311:23) Verify.verifyp7c证书一起使用吗?

0 个答案:

没有答案