This main prompts the user to input a string to be encrypted.

@param args none
@throws Exception on error
330204
public static void main(String[] args) throws Exception {
        EncryptionUtil util = new EncryptionUtil();

        System.out.println("Enter text to encrypt: ");
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String input = reader.readLine();
        if (null != input && !"".equals(input)) {
            System.out.println("'" + util.encrypt(input) + "'");
        }
    }
39286
function encrypt (str) {
    var cipher = crypto.createCipher(algorithm, key)
      , crypted = cipher.update(str, from, to) + cipher.final(to)
    return crypted;
  }
955966
@SuppressWarnings("unused")
	public static void main(String[] args) {
		if (false) {
			long capacity = 1;
			int count = 1;
			while (capacity < Integer.MAX_VALUE) {
				capacity = java.math.BigInteger.valueOf(capacity).nextProbablePrime().longValue();
				System.out.print(capacity + ", ");
				final double inc = Math.log(2) / Math.log(capacity << 5) * 10 + 1;
				// System.out.println(inc);
				capacity *= inc;
				if (count % 5 == 0) {
					System.out.println();
				}
				count++;
			}
			System.out.println(Integer.MAX_VALUE);
			System.out.println("------");

			System.out.println(count);
			System.out.println(PrimeFinder.nextPrime((int) 1e6));
		}
		if (true) {
			IntHashMap<Integer> hash = new IntHashMap<Integer>(16, Integer.class);
			hash.put(1, 2);
			hash.put(2, 4);
			for (Integer i : hash.getValues()) {
				System.out.println(i);
			}
		}
	}
1111575
public static byte[] encryptAsBytes(final String plainText) throws Exception {
        final SecretKey secretKey = KeyManager.getInstance().getSecretKey();
        return encryptAsBytes(secretKey, plainText);
    }
533452
protected String decrypt(String encryptedStr) throws Exception {
        String[] split = encryptedStr.split(":");
        checkTrue(split.length == 3, "Wrong format of the encrypted variable (" + encryptedStr + ")");
        byte[] salt = Base64.getDecoder().decode(split[0].getBytes(UTF8_CHARSET));
        checkTrue(salt.length == saltLengthBytes, "Salt length doesn't match.");
        int iterations = Integer.parseInt(split[1]);
        byte[] encryptedVal = Base64.getDecoder().decode(split[2].getBytes(UTF8_CHARSET));
        return new String(transform(Cipher.DECRYPT_MODE, encryptedVal, salt, iterations), UTF8_CHARSET);
    }
1296905
public static void main(String[] args) {
    org.apache.hadoop.hdfs.DnsMonitorSecurityManager.setTheManager();
    try {
      System.exit(runBalancer(args));
    } catch (Throwable e) {
      LOG.error(StringUtils.stringifyException(e));
      System.exit(-1);
    }

  }
344014
public static void main(String[] args) throws Exception {

        CommandLine cmd = parseArgs(args);

        ensureWritePermissionToLocalDir();

        // Are there credentials?
        Credential credential = null;
        String username = "";
        if (cmd.hasOption("username") || cmd.hasOption("password")) {
            username = cmd.getOptionValue("username");
            credential = getCredentials(username,
                                        cmd.getOptionValue("password"));
        }

        // Where will content be written?
        ContentWriter writer;
        if (cmd.hasOption("cloud-store")) {
            String[] vals = cmd.getOptionValues("cloud-store");
            String host = vals[0];
            String port = vals[1];
            ContentStoreManager mgr = new ContentStoreManagerImpl(host, port);

            if (credential != null) {
                mgr.login(credential);
            }

            writer = new DuracloudContentWriter(mgr.getPrimaryContentStore(),
                                                username);
        } else {
            writer = new FilesystemContentWriter();
        }

        // Will Chunk MD5's be preserved?
        boolean chunkMD5 = true;
        if (cmd.hasOption("exclude-chunk-md5s")) {
            chunkMD5 = false;
        }

        // Will large files be ignored?
        boolean ignoreLarge = false;
        if (cmd.hasOption("ignore-large-files")) {
            ignoreLarge = true;
        }

        // Will files be filtered?
        IOFileFilter fileFilter = TrueFileFilter.TRUE;
        if (cmd.hasOption("file-filter")) {
            String[] filterVals = cmd.getOptionValues("file-filter");
            fileFilter = buildFilter(new File(filterVals[0]));
        }

        // Will directories be filtered?
        IOFileFilter dirFilter = TrueFileFilter.TRUE;
        if (cmd.hasOption("dir-filter")) {
            String[] filterVals = cmd.getOptionValues("dir-filter");
            dirFilter = buildFilter(new File(filterVals[0]));
        }

        // Add content?
        FileChunkerOptions options;
        if (cmd.hasOption("add")) {
            String[] vals = cmd.getOptionValues("add");
            File fromDir = new File(vals[0]);
            File toDir = new File(vals[1]);
            Long chunkSize = getChunkSize(vals[2]);

            options = new FileChunkerOptions(fileFilter,
                                             dirFilter,
                                             chunkSize,
                                             chunkMD5,
                                             ignoreLarge);
            chunk(fromDir, toDir, options, writer);

            // ...or generate test data
        } else if (cmd.hasOption("generate")) {
            String[] vals = cmd.getOptionValues("generate");
            File outFile = new File(vals[0]);
            long contentSize = Long.parseLong(vals[1]);

            FileChunker.createTestContent(outFile, contentSize);

        } else {
            usage();
        }
    }
695501
public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    CompressionCodecFactory factory = new CompressionCodecFactory(conf);
    boolean encode = false;
    for(int i=0; i < args.length; ++i) {
      if ("-in".equals(args[i])) {
        encode = true;
      } else if ("-out".equals(args[i])) {
        encode = false;
      } else {
        CompressionCodec codec = factory.getCodec(new Path(args[i]));
        if (codec == null) {
          System.out.println("Codec for " + args[i] + " not found.");
        } else { 
          if (encode) {
            CompressionOutputStream out = 
              codec.createOutputStream(new java.io.FileOutputStream(args[i]));
            byte[] buffer = new byte[100];
            String inFilename = removeSuffix(args[i], 
                                             codec.getDefaultExtension());
            java.io.InputStream in = new java.io.FileInputStream(inFilename);
            int len = in.read(buffer);
            while (len > 0) {
              out.write(buffer, 0, len);
              len = in.read(buffer);
            }
            in.close();
            out.close();
          } else {
            CompressionInputStream in = 
              codec.createInputStream(new java.io.FileInputStream(args[i]));
            byte[] buffer = new byte[100];
            int len = in.read(buffer);
            while (len > 0) {
              System.out.write(buffer, 0, len);
              len = in.read(buffer);
            }
            in.close();
          }
        }
      }
    }
  }
1037790
private final void encrypt() throws Exception {
        String signStr = Base64Coder.toString(Base64Coder.base64Encode(signature));
        String ud = userData.toString();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(this, tc, "encrypt: userData" + ud);
        }

        byte[] accessID = Base64Coder.getBytes(ud);
        StringBuilder sb = new StringBuilder(DELIM);
        sb.append(getExpiration()).append(DELIM).append(signStr);
        byte[] timeAndSign = getSimpleBytes(sb.toString());
        byte[] toBeEnc = new byte[accessID.length + timeAndSign.length];
        for (int i = 0; i < accessID.length; i++) {
            toBeEnc[i] = accessID[i];
        }
        for (int i = accessID.length; i < toBeEnc.length; i++) {
            toBeEnc[i] = timeAndSign[i - accessID.length];
        }
        try {
            encryptedBytes = LTPAKeyUtil.encrypt(toBeEnc, sharedKey, cipher);
        } catch (Exception e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                Tr.event(this, tc, "Error encrypting; " + e);
            }
            throw e;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(this, tc, "Encrypted bytes are: " + (encryptedBytes == null ? "" : Base64Coder.toString(Base64Coder.base64Encode(encryptedBytes))));
        }
    }
370138
public String encryptText(String text)
	throws Exception
	{
		return toByteText(this.encrypt(text.getBytes(IO.CHARSET)));

	}
1149058
def main(argv: list) -> int:
    """"""
    passphrase = Passphrase()

    # Set defaults
    passphrase.entropy_bits_req = ENTROPY_BITS_MIN
    passwordlen_default = passphrase.password_length_needed()
    amount_n_default = 0
    passphrase.amount_n = amount_n_default
    # To avoid loading the wordlist unnecessarily, I'm hardcoding this value
    # It's ok, it's only used to show help information
    amount_w_default = 6

    parser = ArgumentParser(
        formatter_class=RawDescriptionHelpFormatter,
        description='{version_string}\n\n'
        'Generates a cryptographically secure passphrase, based on '
        'a wordlist, or a\npassword, and prints it to standard output.\n'
        'By default, it uses an embedded EFF Large Wordlist for passphrases.\n'
        'Passphrases with less than {wordsamountmin} words are considered '
        'insecure. A safe bet is \nbetween {wordsamountmin} and 7 words, '
        'plus at least a number.\n'
        'For passwords, use at least {passwdmin} characters, but prefer '
        '{passwdpref} or more, using the\ncomplete characters set.\n\n'
        'Instead of words and numbers, a password (random string of '
        'printable\ncharacters from Python String standard) can be generated '
        'by\n-p | --password, specifying the length. It uses uppercase, '
        'lowercase, digits\nand punctuation characters unless otherwise '
        'specified.\n'
        'Also, a UUID v4 string can be generated by --uuid4 or a coin can be '
        'thrown\nwith --coin.\n'
        'A custom wordlist can be specified by -i | --input, the format must '
        'be: \nsingle column, one word per line. If -d | --diceware is used, '
        'the input\nfile is treated as a diceware wordlist (two columns).'
        '\nOptionally, -o | --output can be used to specify an output file '
        '(existing \nfile is overwritten).\n'
        'The number of words is {wordsamountmin} by default, but it '
        'can be changed by -w | --words.\n'
        'The number of numbers is {numsamountmin} by default, but it can be '
        'changed by\n-n | --numbers. The generated numbers are between '
        '{minnum} and {maxnum}.\n'
        'The default separator is a blank space, but any character or '
        'character\nsequence can be specified by -s | --separator.\n'
        '\nExample output:\n'
        '\tDefault parameters:\tchalice sheath postcard modular cider size\n'
        '\tWords=3, Numbers=2:\tdepraved widow office 184022 320264\n'
        '\tPassword, 20 chars:\tsF#s@B+iR#ZIL-yUWKPR'.format(
            version_string=__version_string__,
            minnum=passphrase.randnum_min,
            maxnum=passphrase.randnum_max,
            wordsamountmin=amount_w_default,
            numsamountmin=amount_n_default,
            passwdmin=passwordlen_default,
            passwdpref=passwordlen_default + 4
        )
    )

    parser.add_argument(
        '--version',
        action='store_true',
        help='print program version and licensing information and exit'
    )
    parser.add_argument(
        '--insecure',
        action='store_true',
        default=False,
        help="force password/passphrase generation even if the system's "
             "entropy is too low"
    )
    parser.add_argument(
        '--no-newline',
        action='store_true',
        default=False,
        help="don't print newline at the end of the passphrase/password"
    )
    parser.add_argument(
        '-m',
        '--mute',
        action='store_true',
        default=False,
        help="muted mode: it won't print output, only informational, warning "
             "or error messages (usefull with -o | --output)"
    )
    parser.add_argument(
        '-v',
        '--verbose',
        action='store_true',
        default=False,
        help='print additional information (can coexist with -m | --mute)'
    )
    parser.add_argument(
        '-e',
        '--entropybits',
        type=_bigger_than_zero,
        default=ENTROPY_BITS_MIN,
        help='specify the number of bits to use for entropy calculations '
             '(defaults to {})'.format(ENTROPY_BITS_MIN)
    )
    parser.add_argument(
        '--uuid4',
        action='store_true',
        default=False,
        help='generate an UUID v4 string'
    )
    parser.add_argument(
        '--coin',
        action='store_true',
        default=False,
        help='generate a random coin throw: heads or tails'
    )
    parser.add_argument(
        '-p',
        '--password',
        type=_bigger_than_zero,
        const=-1,
        nargs='?',
        help='generate a password of the specified length from all printable '
             'or selected characters'
    )
    parser.add_argument(
        '--use-uppercase',
        type=_bigger_than_zero,
        const=0,
        nargs='?',
        help='use uppercase characters for password generation or give the '
             'amount of uppercase characters in the passphrase: zero or no '
             'input for all uppercase or any number of uppercase '
             'characters wanted (the rest are lowercase)'
    )
    parser.add_argument(
        '--use-lowercase',
        type=_bigger_than_zero,
        const=0,
        nargs='?',
        help='use lowercase characters for password generation or give the '
             'amount of lowercase characters in the passphrase: zero or no '
             'input for all lowercase (default) or any number of lowercase '
             'characters wanted (the rest are uppercase)'
    )
    parser.add_argument(
        '--use-digits',
        action='store_true',
        default=False,
        help='use digits for password generation'
    )
    parser.add_argument(
        '--use-alphanumeric',
        action='store_true',
        default=False,
        help='use lowercase and uppercase characters, and digits for password '
             'generation (equivalent to --use-lowercase --use-uppercase '
             '--use-digits)'
    )
    parser.add_argument(
        '--use-punctuation',
        action='store_true',
        default=False,
        help='use punctuation characters for password generation'
    )
    parser.add_argument(
        '-w',
        '--words',
        type=_bigger_than_zero,
        help='specify the amount of words (0 or more)'
    )
    parser.add_argument(
        '-n',
        '--numbers',
        type=_bigger_than_zero,
        default=amount_n_default,
        help='specify the amount of numbers (0 or more)'
    )
    parser.add_argument(
        '-s',
        '--separator',
        type=str,
        default=' ',
        help='specify a separator character (space by default)'
    )
    parser.add_argument(
        '-o',
        '--output',
        type=str,
        help='specify an output file (existing file is overwritten)'
    )
    parser.add_argument(
        '-i',
        '--input',
        type=str,
        help='specify an input file (it must have the following format: '
             'single column, one word per line)'
    )
    parser.add_argument(
        '-d',
        '--diceware',
        action='store_true',
        default=False,
        help='specify input file as a diceware list (format: two colums)'
    )

    args = parser.parse_args(argv)

    inputfile = args.input
    outputfile = args.output
    separator = args.separator
    is_diceware = args.diceware
    passwordlen = args.password
    amount_w = args.words
    amount_n = args.numbers
    show_version = args.version
    mute = args.mute
    verbose = args.verbose
    no_newline = args.no_newline
    gen_uuid4 = args.uuid4
    gen_coin = args.coin
    p_uppercase = args.use_uppercase
    p_lowercase = args.use_lowercase
    p_digits = args.use_digits
    p_punctuation = args.use_punctuation
    p_alphanumeric = args.use_alphanumeric
    entropy_bits = args.entropybits
    gen_insecure = args.insecure

    if show_version:
        print(__version_string__)
        return 0

    if verbose:
        Aux.print_stderr(__version_string__)

    # Check system entropy
    system_entropy = Aux.system_entropy()
    if system_entropy < SYSTEM_ENTROPY_BITS_MIN:
        Aux.print_stderr(
            'Warning: the system has too few entropy: {} bits; randomness '
            'quality could be poor'.format(system_entropy)
        )
        if not gen_insecure:
            Aux.print_stderr(
                'Error: system entropy too low: {system_entropy} '
                '< {system_entropy_min}'.format(
                    system_entropy=system_entropy,
                    system_entropy_min=SYSTEM_ENTROPY_BITS_MIN
                )
            )
            return 1

    if verbose:
        Aux.print_stderr(
            'Using {} bits of entropy for calculations (if any). The minimum '
            'recommended is {}'.format(entropy_bits, ENTROPY_BITS_MIN)
        )

    # Check selected entropy
    check_chosen_entropy = False if gen_uuid4 or gen_coin else not (
        amount_n and amount_w and passwordlen is None
    )
    if check_chosen_entropy and entropy_bits < ENTROPY_BITS_MIN:
        Aux.print_stderr(
            'Warning: insecure number of bits for entropy calculations '
            'chosen! Should be bigger than {}'.format(ENTROPY_BITS_MIN)
        )
    passphrase.entropy_bits_req = entropy_bits

    # Generate whatever is requested
    if gen_uuid4:
        # Generate uuid4
        if verbose:
            Aux.print_stderr('Generating UUID v4')
        gen_what = 'UUID v4'
        gen_ent = 120

        passphrase.generate_uuid4()
        passphrase.separator = '-'
    elif gen_coin:
        # Generate a coin throw
        if verbose:
            Aux.print_stderr('Throwing a coin')
        gen_what = 'coin'
        gen_ent = 1

        passphrase = 'Heads' if randbool() else 'Tails'
    elif passwordlen is not None:
        # Generate a password
        gen_what = 'password'

        p_uppercase = True if p_uppercase is not None else False
        p_lowercase = True if p_lowercase is not None else False
        if (
                p_uppercase
                or p_lowercase
                or p_digits
                or p_punctuation
                or p_alphanumeric
        ):
            passphrase.password_use_uppercase = (p_uppercase or p_alphanumeric)
            passphrase.password_use_lowercase = (p_lowercase or p_alphanumeric)
            passphrase.password_use_digits = (p_digits or p_alphanumeric)
            passphrase.password_use_punctuation = p_punctuation

        min_len = passphrase.password_length_needed()
        if passwordlen < 1:
            passwordlen = min_len
        elif passwordlen < min_len:
            Aux.print_stderr(
                'Warning: insecure password length chosen! Should be bigger '
                'than or equal to {}'.format(min_len)
            )

        passphrase.passwordlen = passwordlen
        gen_ent = passphrase.generated_password_entropy()

        if verbose:
            verbose_string = (
                'Generating password of {} characters long '
                'using '.format(passwordlen)
            )
            verbose_string += (
                'uppercase characters, ' if (
                    passphrase.password_use_uppercase or p_alphanumeric
                ) else ''
            )
            verbose_string += (
                'lowercase characters, ' if (
                    passphrase.password_use_lowercase or p_alphanumeric
                ) else ''
            )
            verbose_string += (
                'digits, ' if (
                    passphrase.password_use_digits or p_alphanumeric
                ) else ''
            )
            verbose_string += (
                'punctuation characters, ' if (
                    passphrase.password_use_punctuation
                ) else ''
            )
            Aux.print_stderr(
                verbose_string[:-2] if (
                    verbose_string[-2:] == ', '
                ) else verbose_string
            )

        passphrase.generate_password()
        passphrase.separator = ''
    else:
        # Generate a passphrase
        gen_what = 'passphrase'

        # Read wordlist if indicated
        if inputfile is None:
            passphrase.load_internal_wordlist()
        else:
            try:
                passphrase.import_words_from_file(inputfile, is_diceware)
            except IOError:
                Aux.print_stderr(
                    "Error: input file {} is empty or it can't be opened or "
                    "read".format(inputfile)
                )
                return 1

        passphrase.amount_n = amount_n
        amount_w_good = passphrase.words_amount_needed()
        if amount_w is None:
            amount_w = amount_w_good
        elif amount_w < amount_w_good:
            Aux.print_stderr(
                'Warning: insecure amount of words chosen! Should be '
                'bigger than or equal to {}'.format(amount_w_good)
            )

        passphrase.amount_w = amount_w
        gen_ent = passphrase.generated_passphrase_entropy()

        if verbose:
            Aux.print_stderr(
                'Generating a passphrase of {} words and {} '
                'numbers using {}'.format(
                    amount_w,
                    amount_n,
                    'internal wordlist' if inputfile is None else (
                        'external wordlist: ' + inputfile + (
                            ' (diceware-like)' if is_diceware else ''
                        )
                    )
                )
            )

        case = (-1 * p_lowercase) if p_lowercase else p_uppercase
        passphrase.generate(case)
        passphrase.separator = separator

    if verbose:
        Aux.print_stderr(
            'The entropy of this {what} is {ent:.2f} bits'.format(
                what=gen_what,
                ent=gen_ent
            )
        )

    if not gen_coin and gen_ent < ENTROPY_BITS_MIN:
        Aux.print_stderr('Warning: the {} is too short!'.format(gen_what))

    if not mute:
        if no_newline:
            print(passphrase, end='')
        else:
            print(passphrase)

    if outputfile is not None:
        # ensure path to file exists or create
        dir_ = os_path_dirname(outputfile)
        if dir_:
            try:
                os_makedirs(dir_, exist_ok=True)
            except PermissionError:
                Aux.print_stderr(
                    'Error: permission denied to create directory {}'.format(
                        dir_,
                    )
                )
                return 1
        try:
            with open(outputfile, mode='wt', encoding='utf-8') as outfile:
                linefeed = '' if no_newline else '\n'
                outfile.write(str(passphrase) + linefeed)

        except IOError:
            Aux.print_stderr(
                "Error: file {} can't be opened or written".format(
                    outputfile,
                )
            )
            return 1

    return 0
1374754
public static void main(String[] args) {
		if (args.length < 2) {
			System.err.println("Two arguments needed as username and password");
			System.exit(-1);
		}
		User user = new User();
		user.name = args[0];
		user.password.setPassword(args[1].toCharArray());
		for (int i = 2; i<args.length; i++) {
			user.roles.add(new UserRole(args[i].trim()));
		}
		System.out.println(user.format());
	}
655944
public static String encryptPassword(@NotNull final String aPlainPass) throws Exception {
        byte[] encBytes = encryptString(aPlainPass.getBytes(DEFAULT_CODEPAGE));
        return Base64.encodeBase64String(encBytes);
    }
1140231
function encrypt(userKey, plainText) {
        var i
          , offset
          , ct = []
          , tmpBlockEncrypt;

        if (utils.isAnArray(userKey) &&
          utils.isAnArray(plainText)) {

          userKey = new Uint8Array(userKey);
          plainText = new Uint8Array(plainText);
        } else {

          throw 'Inputs must be an array';
        }

        userKey = makeKey(userKey);

        for (offset = 0; offset < plainText.length; offset += 16) {

          tmpBlockEncrypt = blockEncrypt(plainText, offset, userKey);
          for (i = 0; i < tmpBlockEncrypt.length; i += 1) {

            ct.push(tmpBlockEncrypt[i]);
          }
        }

        return ct;
      }
165132
public void decrypt(byte[] password) throws GeneralSecurityException {
        if (!isEncrypted()) {
            return;
        }

        byte[] enc = Base64.decode(this.encodedKey);

        SecretKeySpec key = getSecretKey(password, this.initializationVector.getIV());

        Cipher cipher = getCipher();
        cipher.init(Cipher.DECRYPT_MODE, key, this.initializationVector);
        enc = cipher.doFinal(enc);

        this.intKey = getKey(this.keyAlg, enc);
        this.keyData = enc;
        this.isEncrypted = false;
        this.encodedKey = null;
    }
213764
public static String encrypt(String input) {
        try {
            return encrypt(input, null);
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
            return null;
        }
    }
1287191
public void setArgs(String argString)
  {
    try {
      if (argString != null) {
        String []args = Pattern.compile("[\\s,]+").split(argString);

        _args = new ArrayList<String>();

        for (int i = 0; i < args.length; i++) {
          if (! args[i].equals(""))
            _args.add(args[i]);
        }
      }
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);
    }
  }