﻿function RSA256Encrypt(htmlControlId, aspControlId, publicKey, modulus) {
  var htmlControl = document.getElementById(htmlControlId);
  var aspControl = document.getElementById(aspControlId);
  if((htmlControl != null)&&(aspControl != null)&&(publicKey != null)&&(modulus!=null)) {
    setMaxDigits(35);
    key = new RSAKeyPair(
     publicKey,
     "",
     modulus
    );    
    var string = new String();
    var old = new String(htmlControl.value);
    var i,j,blocksNumber,c;
    blocksNumber = Math.ceil(old.length/30);
    for(j=0; j<blocksNumber; j++){
        if(j*30+29>old.length){
          c = old.length;
        } else {
          c = j*30+29;
        }
        for(i=c; i>=j*30; i--){
          string += old.charAt(i);
        }
      }
    aspControl.value = encryptedString(key, string);
  }
} 