Java String Encrypt encrypt(String string)

Here you can find the source of encrypt(String string)

Description

Encrypts the string into a byte array.

License

Open Source License

Parameter

Parameter Description
string String to encrypt

Return

byte array with encrypted string

Declaration

public static byte[] encrypt(String string) 

Method Source Code

//package com.java2s;
/**//from   w  w  w.  j  a  v  a  2s  .c  o  m
 * Copyright (c) 2010-2019 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */

public class Main {
    private static final int KEY = 171;

    /**
     * Encrypts the string into a byte array.
     *
     * @param string String to encrypt
     * @return byte array with encrypted string
     */
    public static byte[] encrypt(String string) {
        byte[] buffer = new byte[string.length()];
        byte key = (byte) KEY;
        for (int i = 0; i < string.length(); i++) {
            buffer[i] = (byte) (string.charAt(i) ^ key);
            key = buffer[i];
        }
        return buffer;
    }
}

Related

  1. encrypt(String s)
  2. encrypt(String s)
  3. Encrypt(String str)
  4. encrypt(String str)
  5. Encrypt(String str, String salt)
  6. encrypt(String string)
  7. encrypt0(final byte[] result)
  8. encryptBankCardNo(String cardNo)
  9. encryptBankCardNoLast4Bits(String cardNo)