Does anyone have an example of taking a string and encrypting it and vise v

I want to encrpyt -> save in my database
then
get value from database --> and then unencrypt
Thanks for your time
Adam

You could look into a Base64 encoding scheme:
//////////////////////license & copyright header/////////////////////////
// Base64 - encode/decode data using the Base64 encoding scheme //
// Copyright (c) 1998 by Kevin Kelley //
// This library is free software; you can redistribute it and/or //
// modify it under the terms of the GNU Lesser General Public //
// License as published by the Free Software Foundation; either //
// version 2.1 of the License, or (at your option) any later version. //
// This library is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU Lesser General Public License for more details. //
// You should have received a copy of the GNU Lesser General Public //
// License along with this library; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA //
// 02111-1307, USA, or contact the author: //
// Kevin Kelley <[email protected]> - 30718 Rd. 28, La Junta, CO, //
// 81050 USA. //
////////////////////end license & copyright header///////////////////////
import java.io.*; // needed only for main() method.
* Provides encoding of raw bytes to base64-encoded characters, and
* decoding of base64 characters to raw bytes.
* @author Kevin Kelley ([email protected])
* @version 1.3
* @date 06 August 1998
* @modified 14 February 2000
* @modified 22 September 2000
public class Base64 {
* returns an array of base64-encoded characters to represent the
* passed data array.
* @param data the array of bytes to encode
* @return base64-coded character array.
static public char[] encode(byte[] data)
char[] out = new char[((data.length + 2) / 3) * 4];
// 3 bytes encode to 4 chars. Output is always an even
// multiple of 4 characters.
for (int i=0, index=0; i<data.length; i+=3, index+=4) {
boolean quad = false;
boolean trip = false;
int val = (0xFF & (int) data);
val <<= 8;
if ((i+1) < data.length) {
val |= (0xFF & (int) data[i+1]);
trip = true;
val <<= 8;
if ((i+2) < data.length) {
val |= (0xFF & (int) data[i+2]);
quad = true;
out[index+3] = alphabet[(quad? (val & 0x3F): 64)];
val >>= 6;
out[index+2] = alphabet[(trip? (val & 0x3F): 64)];
val >>= 6;
out[index+1] = alphabet[val & 0x3F];
val >>= 6;
out[index+0] = alphabet[val & 0x3F];
return out;
* Decodes a BASE-64 encoded stream to recover the original
* data. White space before and after will be trimmed away,
* but no other manipulation of the input will be performed.
* As of version 1.2 this method will properly handle input
* containing junk characters (newlines and the like) rather
* than throwing an error. It does this by pre-parsing the
* input and generating from that a count of VALID input
* characters.
static public byte[] decode(char[] data)
// as our input could contain non-BASE64 data (newlines,
// whitespace of any sort, whatever) we must first adjust
// our count of USABLE data so that...
// (a) we don't misallocate the output array, and
// (b) think that we miscalculated our data length
// just because of extraneous throw-away junk
int tempLen = data.length;
for( int ix=0; ix<data.length; ix++ )
if( (data[ix] > 255) || codes[ data[ix] ] < 0 )
--tempLen;  // ignore non-valid chars and padding
// calculate required length:
// -- 3 bytes for every 4 valid base64 chars
// -- plus 2 bytes if there are 3 extra base64 chars,
// or plus 1 byte if there are 2 extra.
int len = (tempLen / 4) * 3;
if ((tempLen % 4) == 3) len += 2;
if ((tempLen % 4) == 2) len += 1;
byte[] out = new byte[len];
int shift = 0; // # of excess bits stored in accum
int accum = 0; // excess bits
int index = 0;
// we now go through the entire array (NOT using the 'tempLen' value)
for (int ix=0; ix<data.length; ix++)
int value = (data[ix]>255)? -1: codes[ data[ix] ];
if ( value >= 0 ) // skip over non-code
accum <<= 6; // bits shift up by 6 each time thru
shift += 6; // loop, with new bits being put in
accum |= value; // at the bottom.
if ( shift >= 8 ) // whenever there are 8 or more shifted in,
shift -= 8; // write them out (from the top, leaving any
out[index++] = // excess at the bottom for next iteration.
(byte) ((accum >> shift) & 0xff);
// we will also have skipped processing a padding null byte ('=') here;
// these are used ONLY for padding to an even length and do not legally
// occur as encoded data. for this reason we can ignore the fact that
// no index++ operation occurs in that special case: the out[] array is
// initialized to all-zero bytes to start with and that works to our
// advantage in this combination.
// if there is STILL something wrong we just have to throw up now!
if( index != out.length)
throw new Error("Miscalculated data length (wrote " + index + "instead of " + out.length + ")");
return out;
// code characters for values 0..63
static private char[] alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
.toCharArray();
// lookup table for converting base64 characters to value in range 0..63
static private byte[] codes = new byte[256];
static {
for (int i=0; i<256; i++) codes[i] = -1;
for (int i = 'A'; i <= 'Z'; i++) codes[i] = (byte)( i - 'A');
for (int i = 'a'; i <= 'z'; i++) codes[i] = (byte)(26 + i - 'a');
for (int i = '0'; i <= '9'; i++) codes[i] = (byte)(52 + i - '0');
codes['+'] = 62;
codes['/'] = 63;
// remainder (main method and helper functions) is
// for testing purposes only, feel free to clip it.
public static void main(String[] args)
boolean decode = false;
if (args.length == 0) {
System.out.println("usage: java Base64 [-d[ecode]] filename");
System.exit(0);
for (int i=0; i<args.length; i++) {
if ("-decode".equalsIgnoreCase(args[i])) decode = true;
else if ("-d".equalsIgnoreCase(args[i])) decode = true;
String filename = args[args.length-1];
File file = new File(filename);
if (!file.exists()) {
System.out.println("Error: file '" + filename + "' doesn't exist!");
System.exit(0);
if (decode)
char[] encoded = readChars(file);
byte[] decoded = decode(encoded);
writeBytes(file, decoded);
else
byte[] decoded = readBytes(file);
char[] encoded = encode(decoded);
writeChars(file, encoded);
private static byte[] readBytes(File file)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
InputStream fis = new FileInputStream(file);
InputStream is = new BufferedInputStream(fis);
int count = 0;
byte[] buf = new byte[16384];
while ((count=is.read(buf)) != -1) {
if (count > 0) baos.write(buf, 0, count);
is.close();
catch (Exception e) { e.printStackTrace(); }
return baos.toByteArray();
private static char[] readChars(File file)
CharArrayWriter caw = new CharArrayWriter();
try
Reader fr = new FileReader(file);
Reader in = new BufferedReader(fr);
int count = 0;
char[] buf = new char[16384];
while ((count=in.read(buf)) != -1) {
if (count > 0) caw.write(buf, 0, count);
in.close();
catch (Exception e) { e.printStackTrace(); }
return caw.toCharArray();
private static void writeBytes(File file, byte[] data) {
try {
OutputStream fos = new FileOutputStream(file);
OutputStream os = new BufferedOutputStream(fos);
os.write(data);
os.close();
catch (Exception e) { e.printStackTrace(); }
private static void writeChars(File file, char[] data) {
try {
Writer fos = new FileWriter(file);
Writer os = new BufferedWriter(fos);
os.write(data);
os.close();
catch (Exception e) { e.printStackTrace(); }
// end of test code.

Similar Messages

  • Does anyone have an example VI about how to call the animatewindow function in the user32.dll using CLN in Labview?

      I want to call the WinAPI function-animatewindow in user32.dll to produce some special effect when showing or hidding windows, but i don't know how to using this Win API to achieve my purpose?
      Does anyone have an example VI about this application?
      Thanks in advance for your help.

    You have to use the Call Library Function Node to call Windows API functions. The animatewindow function itself has some pretty simple parameters. You first need to get the window handle. There are a set of Windows API Function Utilities (32-bit) for LabVIEW that you can use. In there there is a VI (Get Window Refnum) that gets the window handle. It's a simple call to a Windows API function. You would call the animatewindow function in the same way. In this case there are 3 parameters: the window handle (returned by a FindWindow API call), a DWORD (32-bit integer) for the duration, and another DWORD for the flags.

  • Does anyone have an example code to use mx:ViewStack with my application.

    Does anyone have an example code to use <mx:ViewStack>
    with my application.
    I don't know about how to put value to it and use value in
    it.

    http://livedocs.adobe.com/flex/2/langref/mx/containers/ViewStack.html#includeExamplesSumma ry
    That should be what you're looking for.

  • My Mac has suddenly stopped playing my DVDs including a DVD it played fine only 3 days ago. Does anyone have any idea what could be wrong and how I could fix it? Thank you.

    My Mac has suddenly stopped playing my DVDs including a DVD it played fine only 3 days ago. I insert the DVD and wait for the player to start automatically but after 10 minutes, nothing is happening and it sounds like the disk has stopped spinning. I've now tried with four different DVDs (all store bought and so perfectly normal disks). The Mac doesn't eject the disk or anything it just doesn't seem to respond to it being there at all.
    My main confusion is why this suddenly happened today when it was perfectly fine last week.
    Does anyone have any idea what could be wrong and how I could fix it? Thank you.
    Jinxe

    Welcome to the Apple Support Communities
    See "The drive accepts discs but they do not mount or are automatically ejected" > http://support.apple.com/kb/HT2801

  • Does anyone have a spiraling rainbow image that appears and slow down you computer?

    does anyone have a spiraling rainbow image that appears and seems to slow down the computer?

    Everyone does at one point or another. Please be a little more specific about when this occurs. Also you may find Spinning Beach Ball of Death useful to track down the reason yours is occurring.

  • Does anyone have problems with data usage with att and Iphone5?

    Hello, Does anyone have problems with data usage or non usage I should say with Iphone 5 and AT&T?

    After 4+ months of dealing with this data usage and battery drain problem that included 3 data captures of my wife's iMac, the trigger for us regarding the problems syncing with iCloud, and 5 hours of logs off my iPhone 6 to be analyzed by Apple engineers that included times my wife's computer was both on and off to demonstrate the difference in data usage and battery drain under those conditions, I can say with very reasonable certainty that the iOS 8.3 and corresponding Mac OS 10.10.3 update has solved the problem. 
    We have now been running for about 2 weeks and data usage with the iCloud Servers attempting to sync has dropped from a rate of 31 GBs to under 15 MBs per month.  Yes, you read it right.  We were burning 2000 times as much data doing absolutely nothing important on both of our phones, a 5s and a 6.  Just imagine what that does to battery life!  The 5s would last about 5 hours and the 6 was dead in less than 14.
    The distasteful aspect of this process was how the engineers were quietly fixing the problem at the same time sending messages to my contact person within Apple that were dismissive in nature in the face of indisputable unreasonable results. I must say, this experience with the multiple times the engineers' responses were inappropriate put a little tarnish on the old Apple shine of the ‘It just works’ mantra. This was my first experience in 34 years that caused me to stop recommending Apple products without reservations and with a disclaimer.
    Since the update solved the problem, then I can only conclude that there was a logic bug regarding the reaction within the process to the incoming data that was corrected.  There was noting short of logging out of iCloud that circumvented the problem for us, Gator5000e and probably many others noted on other threads.  I am not trying to imply that this is the cause of everyones battery use problem, but it is reasonable that it was a cause for many.

  • Does anyone have an example to share of using a variable in a proc call?

    I would like to use a value from a table to call a procedure in ActionScript. Can anyone share an example with me? TIA,
    Deb.
    (For example
      var proc_name_from_table:String;
       var command_proc:String;
      command_proc="mx.core.FlexGlobals.TopLevelApplication." + proc_name_from_table;
      command;
    Or something like that (just to give you an idea where I am heading).
    It is for a site map application that gets values from a table and I don't want to write a huge if statement with specific, hard-coded calls.)

    You have to use the Call Library Function Node to call Windows API functions. The animatewindow function itself has some pretty simple parameters. You first need to get the window handle. There are a set of Windows API Function Utilities (32-bit) for LabVIEW that you can use. In there there is a VI (Get Window Refnum) that gets the window handle. It's a simple call to a Windows API function. You would call the animatewindow function in the same way. In this case there are 3 parameters: the window handle (returned by a FindWindow API call), a DWORD (32-bit integer) for the duration, and another DWORD for the flags.

  • Does anyone have an example of a c++ TCP/IP client that works with labview TCP?IP server ??

    I have the labview TCP/IP client/server working fine, but now I need to do this were labview is the TCP/IP server and the c++ program is the client. Does anybody have a simple C++ TCP/IP client that works with labview TCP/IP server ????

    Thanks, you were right, we modified the c++ program to include the port # in the IP address and it worked.We also forgot to convert the port #. I included my labview and c++ program.
    Attachments:
    TCP-IP.llb ‏47 KB
    client.exe ‏40 KB

  • I need a fast buffer which is resizable! Does anyone have an Example how to do that?

    If I use shift registers, I have to say how many elements I want.
    I could use an Array and a local variable and resize the Array all the time, but that is somehow not such a good idea.
    Can Anybody help
    Thank You

    As nobody had an answer I tried something out myself (see atached example). It is a dynamically resizable Buffer not using locals. I also used information of the example FIFO_WO_LocalVar2_6i.vi. Thanks!
    Attachments:
    buffer_rs.vi ‏24 KB

  • Does anyone have an example of an InDesign screenshot on retina Mac?

    I would like to know what InDesign looks like on a retina Mac. Unfortunately I do not live anywhere near a retailer who sells Macs.

    You might want to wait until Adobe updates their product.
    Why don't you ask this question on the Adobe forums instead?
    Other factors you need to consider is now Apple is on a annual OS X upgrade cycle and the future of what OS X will look like is certainly in question as 10.7 and 10.8 introduced a LOT of radical changes, features like Save As...Spaces, scroll bars...removed etc. etc.
    OS X is currently in a state of flux, we don't know why they are doing this, assuming it's new hardware coming of a touchscreen nature for consumers, but it's creating problems for the Mac pro segment who need stability.
    You might want to look at a Windows 7 tower with a nice UltraSharp display, Windows 7 will be supported just like it is with no changes until 2020, that's 8 years verses annual third party software upgrades (paid) and no possible hardware driver upgrades for expensive third party equiptment.
    With Apple on a tear to change OS X and hardware, we don't have a clue what's coming, it's been rather unsettling for the pro market all the way from the Final Cut Pro X debacle to graphic designers who can't afford to replace all their software/hardware so frequently to those who have PPC based apps they require or have lots of file in, and the developers decided to bail since Apple is signaling a closed hardware like on iPads with 10.7+'s AppStore (30% cut to Apple) etc.
    Apple doesn't sell new hardware with a older operating system, we get people here all the time wanting to install Snow Leopard on their new machines and they can't, so we send them to a hack to try to run it in a virtual machine in desperation attempt.
    Apple is a consumer products company where they make most of their revenue at and many professional users are reconsidering their options now due to all the rapid  chaos and changes.
    http://arstechnica.com/apple/2012/01/video-pros-apple-needs-to-acknowledge-the-p ro-industry-and-fast/

  • When restoring from backup does anyone have an issue with old apps reappearing and initializing?

    After upgrading to iTunes v11 none of my devices were recognized. When I restored from a backup I had apps from 2 years ago that installed and initialized

    I see no one has responded, I have the same problem as well except the album art shows when my ipod is connected to itunes, but doesn't show when playing the ipod alone.

  • Some of my apps refuse to open. For example, google crome gives me the message that it quit unexpectedly and gives me the option to submit a report to no resolve. Does anyone have suggestions?

    Some of my apps refuse to open. For example, google crome gives me the message that it quit unexpectedly and gives me the option to submit a report to no resolve. Does anyone have suggestions?

    Welcome to the Apple community.
    Does anyone have suggestions?
    Trash the spyware (Chrome) and use Safari.

  • Anyone have an example of a PCI-6250 Digital and Analog Aquistion with Analog Post-Trigger?

    Hey All,
    We're trying to set up a post trigger data capture of parallel absolute strobed Gurley 17-bit encoder data (ignoring MSB for 16-bit aquisition) with an analog signal that is the output of a torque load cell.  The trick is to use the analog signal level as a post-trigger to stop the data aquisition.
    1) can the analog signal be recorded and used as the trigger?
    2) does anyone have an example using the PCI-6250 (or 6251)
    Thanks in advance for your help,
    -Drewksi 

    Hi Drewski,
    You can use the APFI0 line as an analog trigger for your signal. However, in this case you need to connect your analog signal to both the analog channel you want to acquire at and the APFI0 line.
    Assuming you are using LabVIEW,you can check the "Acq&Graph Voltage-Ext Clk-Analog reference.vi" example. This examples uses an external clock but it works also with the internal clock. All you have to do to change the control to onboard clock.
    You can find this example in LabVIEW Help >> Find Examples >> Hardware Input and Output >> DAQmx >> Analog Measurement >> Voltage
    Best Regards,
    Faris
    Bueller

  • Need 256 Bit AES Full Disk Encryption for a Mac.  The other discussions regarding this issue are very old.  Does anyone have any current advice regarding encryption software?

    Does anyone have any advice regarding 256 bit full disk encryption software for Macs?  The other discussions on the topic are years old, so I would like some current input.  Thanks for your help in advance.

    Depending on your Mac, you might not want to upgrade to OS X 10.7 or 10.8 as it will not run the PowerPC based software your currently using costing a bundle to replace it all, also they will slow down your machine if it's not a more recent issue. You don't want to upgrade OS X without AppleCare defending your possibly bricked logicboard that's for sure.
    Filevault encrypts the boot drive, however in doing so makes it near impossible to fix if you have a software issue and need to recover files directly or by using specialty software. Also it robs the machine of performance even more than the Lions do. So you will really need a SSD to work best with 10.7/10.8 and Filevault, then it has to be freshly installed. Filevault needs 50% free space on the boot drive, then it's going to write to the slower 50% half of the hard drive where performance is terrible compared to the first 50%.
    Also Filevault is cracked under certain conditions, and if someone gets their hands on the machine (like the law) and knows what they are doing.
    If you take your Filevaulted machine to Apple to fix, they are going to require the password to fix the machine obviously.
    Software based encryption is vulnerable, you might want to instead place your sensitive data on external self-encrypting hardware that doesn't rely upon software or computer hacks/bypasses (ike freezing the RAM) to get to it.
    http://www.datalocker.com/products/datalocker-dl3.html
    Iron Keys for portable USB self encryption, both work with any computer, so your not locked into one platform.
    With the senstive data off the computer and on a external device, there is the option of removing, hiding and securing the device. If used with a computer that's never connected to the Internet, it's safe from snoopers, except from a survelliance van parked outside your door.

  • Does anyone have experience with using a Canon Vixia HF M52 Camcorder with Final Cut Express?

    I'm looking to purchase a new camcorder that is compatible with my Mac OS X (10.6.8) that will work well with Final Cut Express 4.0.1  I have downloaded the camcorder support info from Final Cut Express that list many capital camcorders.  I've used Sony tape based camcorders in the past.  I'm looking for High Definition.  I can stick with a tape based camcorder, but thought I would look at the Canon Vixia HF M52 as an alternative, which is listed as compatible.  I would like to download directly from the camera to FCE.  I film in the wilderness, like having an optical zoom of 20 or greater (yes, I use a small tripod). Does anyone have experience with the Canon Vixia?  And if not, but you really like another camcorder that you can recommend, what is it?

    The Vixia HF M52 is an AVCHD camcorder and should work perfectly fine with Final Cut Express 4 (4.0.1).
    The published "camcorder support list" has never been up to date and I would not take it to be a definitive list of compatible camcorders.
    One note, however, the Vixia HF M52 supports a number of different shooting modes.  I suggest sticking with the AVCHD 1920 x 1080i / 60 fps mode for use with FCE.   FCE does not support progressive modes except in 720p25/30 (which the M52 does not seem to shoot anyway); nor does FCE support any 24 fps modes.

Maybe you are looking for

  • InetAddress and hostname containing pause(s)

    Hi! I have a problem to get real host name which contains pause. On Windows NT 4.0 is possible to set NETBIOS name containing pause after a lot of warnings :) It is not good idea to do so, but if some user do it, I'll have to find a way to understand

  • ITunes 10.5 won't add to library OR play any audio files prior to update

    I recently updated to iTunes 10.5 on my MacBook Pro running OS X 10.6.8, and iTunes won't add any of my old music files to the library, regardless of what directory they are in. The permissions on all files and folders of interest are read and write.

  • Retina macbook HDMI issues...

    Hi Ive recently bought a retina macbook and its  an outstanding piece of kit. Unfortunately I've come accross a little glitch with the HDMI port If i plug in my TV via hdmi, the connection temporarily cuts when I move the machine arround . Im just wo

  • Create Customization File in OSB 10g with WLST script

    Is it possible to create a customization file the same as created from the OSB console with a WLST script? Can someone show me the syntax to do this? I need to turn this request around quickly and don't have time for a lot of trial and error. Edited

  • MBean getAttribute throw NullPointerException

    Weblogic:10.3.5 JDK: 1.6.0_29 64bit Please help me figure it out: RuntimeException thrown by rmi server: javax.management.remote.rmi.RMIConnectionImpl.getAttribute(Ljavax.management.ObjectName;Ljava.lang.String;Ljavax.security.auth.Subject;) <Mar 21,