How to use the jsrsasign.asn1 function in jsrsasign

To help you get started, we’ve selected a few jsrsasign examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitpay / bitcore / test / index.js View on Github external
pki_data.length.should.equal(2);


      if (is_browser) {
        var type = 'SHA256';
        var pem = PaymentProtocol.prototype._DERtoPEM(pki_data[0], 'CERTIFICATE');
        var buf = pr.serializeForSig();
        var jsrsaSig = new KJUR.crypto.Signature({
          alg: type + 'withRSA',
          prov: 'cryptojs/jsrsa'
        });
        var signedCert = pki_data[0];
        var der = signedCert.toString('hex');
        // var pem = PaymentProtocol.DERtoPEM(der, 'CERTIFICATE');
        var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
        jsrsaSig.init(pem);
        jsrsaSig.updateHex(buf.toString('hex'));
        jsrsaSig.verify(sig.toString('hex')).should.equal(true);
      } else {
        var crypto = require('crypto');
        var type = 'SHA256';
        var pem = PaymentProtocol.DERtoPEM(pki_data[0], 'CERTIFICATE');
        var buf = pr.serializeForSig();
        var verifier = crypto.createVerify('RSA-' + type);
        verifier.update(buf);
        verifier.verify(pem, sig).should.equal(true);
      }

      // Verify Signature
      var verified = pr.x509Verify();
      verified.should.equal(true);
github bitpay / bitcore / packages / bitcore-payment-protocol / lib / browser.js View on Github external
return chain.every(function(cert, i) {
    var der = cert.toString('hex');
    var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
    var name = RootCerts.getTrusted(pem);

    var ncert = chain[i + 1];
    // The root cert, check if it's trusted:
    if (!ncert || name) {
      if (!name) {
        return false;
      }
      chain.length = 0;
      return true;
    }
    var nder = ncert.toString('hex');
    var npem = KJUR.asn1.ASN1Util.getPEMStringFromHex(nder, 'CERTIFICATE');

    // Get Next Certificate:
    var ndata = new Buffer(nder, 'hex');
    var nc = rfc5280.Certificate.decode(ndata, 'der');

    var npubKey;
    // Get Public Key from next certificate (via KJUR because it's a mess):
    if (sigHashAlg !== 'none') {
      var js = new KJUR.crypto.Signature({
        alg: sigHashAlg + 'withRSA',
        prov: 'cryptojs/jsrsa'
      });
      js.init(npem);
      npubKey = js.pubKey;
    }
github hyperledger-archives / fabric / sdk / node / lib / hfc.js View on Github external
process.env['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA';
var debugModule = require('debug');
var fs = require('fs');
var urlParser = require('url');
var grpc = require('grpc');
var util = require('util');
var jsrsa = require('jsrsasign');
var elliptic = require('elliptic');
var sha3 = require('js-sha3');
var BN = require('bn.js');
var crypto = require("./crypto");
var stats = require("./stats");
var sdk_util = require("./sdk_util");
var events = require('events');
var debug = debugModule('hfc'); // 'hfc' stands for 'Hyperledger Fabric Client'
var asn1 = jsrsa.asn1;
var asn1Builder = require('asn1');
var _caProto = grpc.load(__dirname + "/protos/ca.proto").protos;
var _fabricProto = grpc.load(__dirname + "/protos/fabric.proto").protos;
var _chaincodeProto = grpc.load(__dirname + "/protos/chaincode.proto").protos;
var net = require('net');
var DEFAULT_SECURITY_LEVEL = 256;
var DEFAULT_HASH_ALGORITHM = "SHA3";
var CONFIDENTIALITY_1_2_STATE_KD_C6 = 6;
var _chains = {};
// A request to get a batch of TCerts
var GetTCertBatchRequest = (function () {
    function GetTCertBatchRequest(name, enrollment, num, attrs) {
        this.name = name;
        this.enrollment = enrollment;
        this.num = num;
        this.attrs = attrs;
github hyperledger-archives / fabric / sdk / node / hlc.js View on Github external
*    For the default implementation, see MemberServices.
 *    NOTE: This makes member services pluggable from the client side, but more work is needed to make it compatible on
 *          the server side transaction processing path depending on how different the implementation is.
 */

var debug = require('debug')('hlc');   // 'hlc' stands for 'HyperLedger Client'
var fs = require('fs');
var urlParser = require('url');
var grpc = require('grpc');
var events = require('events');
var util = require('util');

//crypto stuff
var jsrsa = require('jsrsasign');
var KEYUTIL = jsrsa.KEYUTIL;
var asn1 = jsrsa.asn1;
var elliptic = require('elliptic');
var sha3_256 = require('js-sha3').sha3_256;
var sha3_384 = require('js-sha3').sha3_384;
var kdf = require(__dirname+'/kdf');

var _caProto = grpc.load(__dirname + "/protos/ca.proto").protos;
var _fabricProto = grpc.load(__dirname + "/protos/fabric.proto").protos;
var _timeStampProto = grpc.load(__dirname + "/protos/google/protobuf/timestamp.proto").google.protobuf.Timestamp;
var _chains = {};

var DEFAULT_TCERT_BATCH_SIZE = 200;

/**
 * Create a new chain.  If it already exists, throws an Error. 
 * @param name {string} Name of the chain.  It can be any name and has value only for the client.
 * @returns
github hyperledger / fabric-sdk-node / test / unit / headless-tests.js View on Github external
'roles':null,
	'affiliation':'',
	'enrollmentSecret':'',
	'enrollment': {
		'signingIdentity': '0e67f7fa577fd76e487ea3b660e1a3ff15320dbc95e396d8b0ff616c87f8c81a',
		'identity': {
			'id': 'testIdentity',
			'certificate': TEST_KEY_PRIVATE_CERT_PEM
		}
	}
};

var jsrsa = require('jsrsasign');
var KEYUTIL = jsrsa.KEYUTIL;
var ECDSA = jsrsa.ECDSA;
var asn1 = jsrsa.asn1;

var CryptoSuite_ECDSA_AES = require('fabric-client/lib/impl/CryptoSuite_ECDSA_AES.js');
var ecdsaKey = require('fabric-client/lib/impl/ecdsa/key.js');
var api = require('fabric-client/lib/api.js');
var elliptic = require('elliptic');
var BN = require('bn.js');
var Signature = require('elliptic/lib/elliptic/ec/signature.js');
var PKCS11 = require('fabric-client/lib/impl/bccsp_pkcs11.js');

const halfOrdersForCurve = {
	'secp256r1': elliptic.curves['p256'].n.shrn(1),
	'secp384r1': elliptic.curves['p384'].n.shrn(1)
};

test('\n\n** utils.getCryptoSuite tests **\n\n', (t) => {
	var cs = utils.getCryptoSuite({keysize: 384, algorithm: 'EC'}, keyValStorePath5);
github hyperledger / fabric-sdk-node / test / unit / ecdsa-key.js View on Github external
*
 * SPDX-License-Identifier: Apache-2.0
 */

'use strict';

const tape = require('tape');
const _test = require('tape-promise').default;
const test = _test(tape);

const testutil = require('./util.js');
const ecdsaKey = require('fabric-client/lib/impl/ecdsa/key.js');

const jsrsa = require('jsrsasign');
const KEYUTIL = jsrsa.KEYUTIL;
const asn1 = jsrsa.asn1;
const X509 = require('x509');

test('\n\n ** ECDSA Key Impl tests **\n\n', (t) => {
	testutil.resetDefaults();

	t.throws(
		() => {
			new ecdsaKey();
		},
		/^Error: The key parameter is required by this key class implementation, whether this instance is for the public key or private key/,
		'ECDSA Impl test: catch missing key param'
	);

	t.throws(
		() => {
			new ecdsaKey('dummy private key');
github hyperledger / fabric-sdk-node / fabric-common / lib / impl / ecdsa / key.js View on Github external
/*
 Copyright 2016, 2018 IBM All Rights Reserved.

 SPDX-License-Identifier: Apache-2.0

*/

'use strict';

const {HashPrimitives, Key, Utils: utils} = require('../../../');
const jsrsa = require('jsrsasign');
const asn1 = jsrsa.asn1;
const KEYUTIL = jsrsa.KEYUTIL;
const ECDSA = jsrsa.ECDSA;
const jws = jsrsa.jws;
const logger = utils.getLogger('ecdsa/key.js');

/**
 * This module implements the {@link module:api.Key} interface, for ECDSA.
 * @class ECDSA_KEY
 * @extends module:api.Key
 */
module.exports = class ECDSA_KEY extends Key {
	/**
	 * this class represents the private or public key of an ECDSA key pair.
	 *
	 * @param {Object} key This must be the "privKeyObj" or "pubKeyObj" part of the object generated by jsrsasign.KEYUTIL.generateKeypair()
	 */
github xuehuiit / fabric-explorer / fabric-ca-client / lib / FabricCAClientImpl.js View on Github external
http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/

'use strict';

var api = require('./api.js');
var utils = require('./utils.js');
var util = require('util');
var jsrsa = require('jsrsasign');
var asn1 = jsrsa.asn1;
var path = require('path');
var http = require('http');
var https = require('https');
var urlParser = require('url');


var logger = utils.getLogger('FabricCAClientImpl.js');

/**
 * @typedef {Object} TLSOptions
 * @property {string[]} trustedRoots Array of PEM-encoded trusted root certificates
 * @property {boolean} [verify=true] Determines whether or not to verify the server certificate when using TLS
 */

/**
 * This is an implementation of the member service client which communicates with the Fabric CA server.
github hyperledger / fabric-sdk-node / lib / impl / MemberServices.js View on Github external
http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/

'use strict';

var api = require('../api.js');
var utils = require('../utils');
var jsrsa = require('jsrsasign');
var asn1 = jsrsa.asn1;
var path = require('path');
var grpc = require('grpc');
var _caProto = grpc.load(path.join(__dirname, '../../lib/protos/ca.proto')).protos;

var logger = utils.getLogger('MemberServices.js');

/**
 * This is the default implementation of a member services client.
 *
 * @class
 */
var MemberServices = class extends api.MemberServices {

	/**
	 * constructor
	 *
github hyperledger / fabric-sdk-node / fabric-ca-client / lib / impl / ecdsa / key.js View on Github external
http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/

'use strict';

var Ber = require('asn1').Ber;
var Hash = require('../../hash.js');
var utils = require('../../utils.js');
var jsrsa = require('jsrsasign');
var asn1 = jsrsa.asn1;
var KEYUTIL = jsrsa.KEYUTIL;
var ECDSA = jsrsa.ECDSA;

var logger = utils.getLogger('ecdsa/key.js');

/*
 * This module implements the {@link module:api.Key} interface, for ECDSA.
 * @module ECDSA_KEY
 */
module.exports = class ECDSA_KEY {
	/*
	 * this class represents the private or public key of an ECDSA key pair.
	 *
	 * @param {Object} key This must be the "privKeyObj" or "pubKeyObj" part of the object generated by jsrsasign.KEYUTIL.generateKeypair()
	 */
	constructor(key, keySize) {

jsrsasign

opensource free pure JavaScript cryptographic library supports RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp and CAdES and JSON Web Signature(JWS)/Token(JWT)/Key(JWK)

MIT
Latest version published 11 months ago

Package Health Score

74 / 100
Full package analysis