How to use AES.encrypt/AES.decrypt?

Posted on
  • Can someone please explain me how to generate the key?

    key - Key to encrypt message - must be an ArrayBuffer of 128, 192, or
    256 BITS

  • Try something like this

    //RNG.js
    
    // Generates a 16 byte block of random numbers using AES
     //RNG.js
    function RNG(){
     this.key1=new Uint8Array(16);
     this.R=new Uint8Array(16);
     this.plain=new Uint8Array(16);
    }//end RNG
    
    RNG.prototype.random=function(A){
    var i;
    E.srand(E.hwRand()); //randomize
      for(i=0;i<16;i++)this.plain[i]=(Math.ran­dom()*256)%256;
      this.R=AES.encrypt(this.plain,this.key1)­;
      for(i=0;i<16;i++)A[i]=this.R[i];
    };//end random
    
    RNG.prototype.setup_random=function(){
     for(var i=0;i<16;i++){
      E.srand(E.hwRand());
      this.key1[i]=parseInt((Math.random()*256­),10);
     }
    };//end setup_random
    
    //exports = RNG;
    
    
    function testit(){
     var i;
     var A=new Uint8Array(16);
    // var W=new (require("RNG"))();
     var W=new RNG();
     W.setup_random();
      for(i=0;i<16;i++){
       W.random(A);
       console.log(A);
      }
    }
    
    testit();
    
  • Thanks @ClearMemory041063 - @sureshkm you basically just need to generate a random series of bytes for the array, as in the code above.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to use AES.encrypt/AES.decrypt?

Posted by Avatar for sureshkm @sureshkm

Actions