0

I have issue related to cryptography in angular 2, I am using "cryptojs javascript" library javascript library and use SHA512 method for encryption data but is shows "Crypt is not a constructor".

Below is my code

Include javascript library in index.html

<script type="text/javascript" src="http://cryptojs.altervista.org/api/functions_cryptography.js"></script>

Component File

import { Component } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { AppService } from './app.service';
import { AppSettings } from './app.settings';
import { CartService } from './service/cart.service';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { DialogRef, ModalComponent, CloseGuard } from 'angular2-modal';
import { Modal, BSModalContext } from 'angular2-modal/plugins/bootstrap';
import { Overlay, overlayConfigFactory } from 'angular2-modal';
import { MessageModalContext, MessageModal } from './message-modal.component';
declare var Crypt: any;
export class OrderReviewComponent {

 constructor(
    private appService: AppService,
    private router: Router,
    private route: ActivatedRoute,
    public modal: Modal,
    private _cartService: CartService,
) {}

 Order(cartinfo) {
            var Crypt = new Crypt();
            var digest_sha512 = Crypt.HASH.sha512('gtKFFx|4942618|10|[{"name":"abc","description":"abcd","value":"5"},{"name":"xyz","description":"wxyz","value":"2"}]|abc|[email protected]|||||||||||eCwWELxi');
            console.log(digest_sha512.toString());
            this.removecartitem(cartinfo, 2); // status 2 means cancel order click
        }
 }

Thanks in advance

Vikram

2
  • 1
    var Crypt = new Crypt(); - try changing all occurrences of Crypt with crypt - except in new Crypt() - you essentially are "clobbering" the Crypt object with your var Crypt Commented Nov 30, 2016 at 8:04
  • hey @Jaromanda X please post this as an answer... This was the problem... I picked from this link cryptojs.altervista.org/api/#.WKL0WxJ97xR . I would be glad to upvote you. Commented Feb 14, 2017 at 12:34

1 Answer 1

1

you only need to declare the veriable in global

var Crypt = new Crypt();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.