Set encryption type and password
554803
def encryption_key_set(enctype, password)
      password = Utils.add_quotes(password)
      # if enctype is TACACS_SERVER_ENC_UNKNOWN, we will unset the key
      if enctype == TACACS_SERVER_ENC_UNKNOWN
        # if current encryption type is not TACACS_SERVER_ENC_UNKNOWN, we
        # need to unset it. Otherwise the box is not configured with key, we
        # don't need to do anything
        if encryption_type != TACACS_SERVER_ENC_UNKNOWN
          config_set('tacacs_server', 'encryption', state:  'no',
                                                    option: encryption_type,
                                                    key:    encryption_password)
        end
      else
        config_set('tacacs_server', 'encryption', state: '', option: enctype,
                    key: password)
      end
    end
279772
def set_user_passwd(self, userid, data):
        """"""
        return self.api_call(
            ENDPOINTS['users']['password'],
            dict(userid=userid),
            body=data)
1022610
public void setKeyStore(String keyStore, String keyPass, String keyManagerType, String keyStoreType) 
    {
        if((keyStore == null) || (keyPass == null))
        {
            this.keyStore =  System.getProperty("javax.net.ssl.keyStore");
            this.keyPass = System.getProperty("javax.net.ssl.keyStorePassword");
        }
        else
        {
            this.keyStore = keyStore;
            this.keyPass = keyPass;
        }
        
        if (keyManagerType != null) {
            this.keyManagerType = keyManagerType;
        }
        if (keyStoreType != null) {
            this.keyStoreType = keyStoreType;
        }
        isKeyStoreSet = (keyStore != null) && (keyPass != null);
    }
225765
def handle_get_passphrase(self, conn, _):
        """"""
        p1 = self.client.device.ui.get_passphrase('Symmetric encryption:')
        p2 = self.client.device.ui.get_passphrase('Re-enter encryption:')
        if p1 == p2:
            result = b'D ' + util.assuan_serialize(p1.encode('ascii'))
            keyring.sendline(conn, result, confidential=True)
        else:
            log.warning('Passphrase does not match!')
1004556
function setEncryption($userPass = '', $ownerPass = '', $pc = array()) {
    $p = bindec("11000000");

    $options =  array('print'=>4, 'modify'=>8, 'copy'=>16, 'add'=>32);

    foreach($pc as  $k=>$v) {
      if  ($v &&  isset($options[$k])) {
        $p+= $options[$k];
      } else  if  (isset($options[$v])) {
        $p+= $options[$v];
      }
    }

    // implement encryption on the document
    if  ($this->arc4_objnum ==  0) {
      // then the block does not exist already, add it.
      $this->numObj++;
      if  (mb_strlen($ownerPass) == 0) {
        $ownerPass = $userPass;
      }

      $this->o_encryption($this->numObj, 'new', array('user'=>$userPass, 'owner'=>$ownerPass, 'p'=>$p));
    }
  }
1161203
def enable_encryption(self, output_key, input_key):
        """"""
        self._chacha = chacha20.Chacha20Cipher(output_key, input_key)
1271039
def encrypt(passwd):
    
    m = sha1()
    salt = hexlify(os.urandom(salt_len))
    m.update(unicode2bytes(passwd) + salt)
    crypted = bytes2unicode(salt) + m.hexdigest()
    return crypted
427893
private void save() {
    Preferences pref = Preferences
        .userNodeForPackage(ConnectionDialog.class);

    pref.put("host", getHost());
    pref.put("user", getUser());

    boolean remember = getRememberPasswordCheckBox().isSelected();
    if (remember) {
      try {
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        KeyGenerator keygen = KeyGenerator.getInstance("AES");
        SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
        random.setSeed(new byte[]{
          0x60, (byte) 0xFD, 0x28, 0x07, 0x35, 0x4A, 0x0D, 0x3B
        });
        byte[] iv = new byte[16];
        random.nextBytes(iv);
        IvParameterSpec spec = new IvParameterSpec(iv);
        keygen.init(128, random);
        cipher.init(Cipher.ENCRYPT_MODE, keygen.generateKey(), spec);
        byte[] clearText = getPassword().getBytes();
        byte[] cipherText = cipher.doFinal(clearText);
        pref.putByteArray("password", cipherText);
        pref.putBoolean("remember", true);
      } catch (Exception e) {
        logger.error("Could not encrypt password", e);
        pref.remove("password");
        pref.putBoolean("remember", false);
      }
    } else {
      pref.remove("password");
      pref.putBoolean("remember", false);
    }
  }
198135
function encrypt(salt, password) {
    var hash = crypto.createHash('sha256').update(salt + password).digest('base64');
    return salt + hash;
}
1343683
def _set(self, jsonData) :
        """"""
        
        self["username"] = jsonData["user"]
        self["active"] = jsonData["active"]
        self["extra"] = jsonData["extra"]
        try:
            self["changePassword"] = jsonData["changePassword"]
        except Exception as e:
            pass
            # self["changePassword"] = ""
        
        try :
            self["password"] = jsonData["passwd"]
        except KeyError :
            self["password"] = ""

        self.URL = "%s/user/%s" % (self.connection.URL, self["username"])
241471
public static void encryptFile(File raw, File encryptedFile, String password) throws IOException {
        byte[] b = readBytes(raw);
        String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
        byte[] encryptedBytes = new RNCryptorNative().encrypt(encodedImage, password);
        writeBytes(encryptedFile, encryptedBytes);
    }
468476
def set_password(self, service, username, password):
        
        service = escape_for_ini(service)
        username = escape_for_ini(username)

        # encrypt the password
        password = password or ''
        password_encrypted = self.encrypt(password.encode('utf-8'))

        # encode with base64
        password_base64 = base64.encodestring(password_encrypted).decode()
        # write the modification
        if not self.config.has_section(service):
            self.config.add_section(service)
        self.config.set(service, username, password_base64)
        config_file = UnicodeWriterAdapter(self._open('w'))
        self.config.write(config_file)
        config_file.close()
870508
def generate_password():
    
    chars = uppercase + lowercase + digits
    return ''.join(SystemRandom().choice(chars) for x in xrange(16))
331788
def encrypt(data, opts={})
      salt = generate_salt(opts[:salt])
      setup_cipher(:encrypt, salt)
      e = cipher.update(data) + cipher.final
      e = "Salted__#{salt}#{e}" #OpenSSL compatible
      opts[:binary] ? e : Base64.encode64(e)
    end
690608
function writeKey(key, value, masterPassword) {
    var contents = getContents(masterPassword);
    contents[key] = value;
    var fileContents = JSON.stringify(contents);
    var encryptedFileContents = encryption.encrypt(fileContents, masterPassword);
    file.writeToFile(encryptedFileContents);
}
1263925
def encrypt(self):
        
        value = self.parameters.get("Plaintext")
        if isinstance(value, six.text_type):
            value = value.encode('utf-8')
        return json.dumps({"CiphertextBlob": base64.b64encode(value).decode("utf-8"), 'KeyId': 'key_id'})
1099638
private String encryptPassword(String password)
            throws AuthenticationException {
        byte[] passwordBytes = password.getBytes();

        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(passwordBytes);

            byte messageDigest[] = algorithm.digest();
            BigInteger number = new BigInteger(1, messageDigest);

            password = number.toString(16);
            if (password.length() == 31) {
                password = "0" + password;
            }
        } catch (Exception e) {
            throw new AuthenticationException(
                    "Internal password encryption failure: " + e.getMessage());
        }
        return password;
    }