Here you can find the source of encrypt(String string)
Parameter | Description |
---|---|
string | String to encrypt |
public static byte[] encrypt(String string)
//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; } }