What about encrypt some text/string

What about encrypt a string. I'm troubled to use javax.crypt or java.security. Is anyone would show me how? Just give some example ho to use it. Thank you for all.

I've try something like this :
static JFrame Frame;
static JPanel Panel;
static JLabel Judul;
static JTextArea Terang, Sandi;
static JButton OK;
static Insets lokasi;
static Cipher ecipher,dcipher;
try {
// Generate a DES key
KeyGenerator keyGen = KeyGenerator.getInstance("DES");
SecretKey key = keyGen.generateKey();
//Terang.setText(key.toString());
ecipher = Cipher.getInstance("DES");
dcipher = Cipher.getInstance("DES");
ecipher.init(Cipher.ENCRYPT_MODE, key);
ecipher.init(Cipher.DECRYPT_MODE, key);
// Encode the string into bytes using utf-8
String str="AMRI SHODIQ";
byte[] utf8 = str.getBytes("UTF8");
Terang.setText(utf8.toString());
// Encrypt
byte[] enc = ecipher.doFinal(utf8);
// Encode bytes to base64 to get a string
Sandi.setText(enc.toString());
byte[] dec = dcipher.doFinal(Sandi.getText().getBytes());
str =new String(utf8, "UTF8");
Terang.setText(str);
} catch (javax.crypto.NoSuchPaddingException e) {
} catch (java.security.NoSuchAlgorithmException e) {
} catch (java.security.InvalidKeyException e) {
} catch (IllegalBlockSizeException e) {
} catch (UnsupportedEncodingException e) {
} catch (javax.crypto.BadPaddingException e) {
The compiling was going well but the the result is not what i expected to have. Please give me a favour correcting this code

Similar Messages

  • Write text string using actionscript?

    Hi,
    I'm rather new at actionscript. I know I can do this in
    javaScript using "document.write" but I don't seem to be having any
    luck with actionscript.
    I'd like to include some text strings that display within a
    actionscript function.
    I have a dynamic text field called "pagecount".
    The function is:
    function onEnterFrame()
    pagecount.text = _parent._parent.rdinfoSlideCount;
    I want to include text that says to the user "You are now on
    page _____ (results of the function)."
    With JavaScript it might look something like this:
    function onEnterFrame()
    pagecount.text = document.write("You are now on page ") +
    _parent._parent.rdinfoSlideCount;
    This doesn't work.
    What would be the syntax to add text to the actionscript
    function?
    Thank you,
    TPK

    If I understand, then this would do it:
    pagecount.text = "You are now on page " +
    _parent._parent.rdinfoSlideCount;
    Dave -
    Head Developer
    www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • Converting multiline text string to single line

    How do I convert a multiline text string into a single line text string

    Hi Bart,
    what's a multiline text string?
    1) You have an array of string: simply use "string concatenate" to convert from array to scalar string.
    2) Your string contains CR and/or NL characters: use "Search/Replace..." for this string, replace all EndOfLine chars by space (or which char you may prefer)...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Apple script to build text string

    quick question.. how do i go about building a text string from dialog box results?
    ie 1st question asks for a username second a unix path.
    the put that in a text string to run in a shell script

    Use a construct such as:
    set answer_1 to text returned of (display dialog "Question 1" default answer "")
    set answer_2 to text returned of (display dialog "Question 2" default answer "")
    do shell script answer_1 & answer_2
    (50002)

  • Yesterday Colloquy crashed on my iPad after an Arabic text string was pasted into the IRC channel that I was on. Another user using Linkinus was also affected. As I understand it, this vulnerability has to do with Webkit. What is being done about it?

    Yesterday Colloquy crashed on my iPad after an Arabic text string was pasted into the IRC channel that I was on. Another user using Linkinus under Mountain Lion on her Macbook Pro was also affected. As I understand it, this vulnerability has to do with applications that use Webkit. What is being done about it? Can we expect security updates for Mountain Lion and iOS 6 soon?

    AFAIK, there has not been an update regarding this issue as yet.
    Rendering bug crashes OS X, iOS apps with string of Arabic characters (Updated) | Ars Technica
    You can send feedback to Apple >  Apple - Mac OS X - Feedback

  • I have a acrobat reader, can I import text delimited data format to a PDF Form so that it can auto fill into forms that was created? If not, what about FDF and XML data

    I have a acrobat reader, can I import text delimited data format to a PDF Form so that it can auto fill into forms that was created? If not, what about FDF and XML data

    Yes, you can do all of that via Tools - Forms - More Form Options - Import Data, if you have Acrobat.
    If you only have the free Reader then you can still do it, but it requires a script.

  • My apple hard drive has 450 gigs of other what could that be? and how could I go about deleating some of it?

    so I have a 1 TB hard drive and I am trying to edit some stuff from my go pro and when looking to free up space on my hardrive it shows on about this mac that there is 453.97 gigs of other what could all this be? How could I go about deleating some of it?
    Also when I dupdated to osx 10 the folder windows no longer show how much free space on the hard drive at the bottom like it use to which was verry handy is there any way that I could get that to show up agian?

    OmniDiskSweeper is a good program to see what's taking up space: http://www.omnigroup.com/products/omnidisksweeper/

  • Hello i need a help about script to export translatable text strings from ai files and import them back

    Hello i need a help about script to export translatable text strings from ai files and import them back after editing, thanks in advance

    Lanny -
    Thank you for taking the time to help with this problem. Can I just say however that as someone who has posted a first comment here and quite clearly never used a forum like this before, your comment unfortunately comes across as very excluding. It makes me feel there are a set of unwritten rules that I should know, and that I don't know them shows that the forum is not for me. In short, it's exactly the kind of response that stops people like me using forums like this.
    I'm sure it's not intended to be received like this and I am sure that the way you have responded is quite normal in the rules of a forum like this. However, it is not normal for those of us who aren't familiar with forums and who only encounter them when they have a genuine problem. This is why I hope it is helpful to respond in full.
    The reason I posted here is as follows. I was directed here by the apple support website. The original comment seemed to be the only one I could find which referred to my issue. As there is no obvious guidance on how to post on a forum like this it seemed perfectly reasonable to try and join in a conversation which might solve more than one problem at once.
    Bee's reply however is both helpful and warm. This could in fact be a template for how new members should be welcomed and inducted into the rules of the forum in a friendly and inclusive way. Thank you very much indeed Bee!

  • HT1688 If I'm in Mexico and I'm skyping with someone in the US, will it go against my data plan or is it free? What about text messaging?

    If I'm in Mexico and skyping with someone in the US, will it go against my data plan? What about text messaging?

    Unless you are connected to an available wi-fi network when Skyping, when doing so via a carrier's cellular network goes against your data plan. The same when using any app that requires internet access.
    SMS is exchanged over the same network as calls, so no data usage with SMS.
    MMS is exchanged over the carrier's cellular data or internet network so MMS goes against your data plan.
    The same when exchanging iMessages unless your are connected to an available wi-fi network when doing so.

  • I had a text string and it disappeared.  What happened

    I had a text string with someone last night and now it disappeared.  what happened?

    Did you erase it?

  • What about Full-text indexing and search?

    Great idea!
    Has ORACLE NoSQL db this feature?
    What about indexing/search using multiple languages simultaneously?
    Thank you.

    Hello Oleg,
    Oracle NoSQL Database does not have these features. We may be considering them in a future release.
    Charles Lamb

  • How do I get out of kernel panic?  kernel panic upon boot.  I did that hard drive cleanup and reinstalled Lion.  What about memory?  Anyone think I need to upgrade my memory?  I have 8gig.

    I get kernel paic upon boot.  I did that hard drive cleanup and reinstalled Lion.  What about memory?  Anyone think I need to upgrade my memory?  I have 8 G of upgraded RAM. (20 inch iMac core 2 duo)

    If you're able to boot, launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ If you’re running Mac OS X 10.7 or later, open LaunchPad. Click Utilities, then Console in the page that opens.
    Select the most recent panic log under System Diagnostic Reports. Post the contents — the text, please, not a screenshot. For privacy’s sake, I suggest you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header and body of the report, if it’s present (it may not be.) Please don't post "shutdownStall" or "hang" reports.
    If you can't boot in the usual way, try a safe boot. The instructions provided by Apple are as follows:
    Be sure your Mac is shut down.
    Press the power button.
    Immediately after you hear the startup tone, hold the Shift key. The Shift key should be held as soon as possible after the startup tone, but not before the tone.
    Release the Shift key when you see the gray Apple icon and the progress indicator (looks like a spinning gear).
    During startup, you’ll see a progress bar, and then the login screen, which appears even if you normally log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Safe mode is slower than normal, and some things won’t work at all.
    Note: If FileVault is enabled under Mac OS X 10.7 or later, you can’t boot in safe mode.

  • How To Color a Text string using Regex (java.util.regex)

    Hello,
    How can I color a text string using regex class in 1.4?

    Yes, did you notice it said something about incredibly vague functionality?
    Let me break it down for you
    > How can I color a text string
    Strings do not have color... You can color a component (a label, a button), but you can't color a string
    > using regex class in 1.4?
    Using a regular expression? How would a regular exression color anything? Do you have embedded color codes? Are you searhing a string for some secret word?
    What are you talking about?

  • Encrypt message text friendly

    I have a simple class to make encryption/decryption of string data using a cipher. However, when looking at the crypted text, it's all a bunch of cryptic characters:
    Original string: Hello World!
    Crypted string: ��?H?�s v���?
    The algortihm i'm using is DES provided by javax.crypto. I need to store this text in some email message or other text container and i have problem with certains characters that are not well understood on another machine.
    Is there a way to encrypt the string so that it is text friendly, i.e. that it use only letters and numbers to generate the crypted output?
    Something like the MIME format.

    Not much looked at the different algorithms, but to
    what i see they all crypt with blocks of bytes and
    don't matter in what range the generated bytes are. Cryptography converts streams of bits into other, essentially randomized, streams of bits. If your crypto is correct, there is no order or range-limitation on the ciphertext.
    There must be a way to filter the outputted bytes so
    that a call to encrypt with one of a such algorithm
    would produce the needed result.Nope - not unless your enciphering algorithm is awful.
    Another reason why i'm doing this is to pass encrypted
    portions of url into a browser without falling into
    illegal characters. I've implemented a way to do it by
    converting the generated bytes into hex characters.
    It's not much efficient, cause it takes 2 times the
    original length of the string, but it works fine for
    small strings.Base64 exists precisely to allow for the transfer of random binary data (like ciphertexts) through a text-only medium (like HTTP). The standard procedure is to encrypt- Base64encode - transport - receive - Base64decode - decrypt. Along the way, you can write out your Base64 data and read it, since by definition is consists only of readable characters.
    It will, as floersh notes, enlarge your data by 4/3s along the way.
    Good luck!
    Grant

  • Some text in my smartform is not aligned or one space below

    Hello Experts,
    I am currently modifying a smartform wherein some of the text is
    one space below its correct alignment. For example:
    Particulars      Quantity     Price
                       50         
    Enervon Prime                 1,000
    The 50 must be aligned with the particular and price. When I checked the
    form, it doesnt have anyspace and the variable is inserted immediately. No spaces
    or indentions whatsoever. Help would be greatly appreciated guys as this is very urgent.
    Thank you and take care!

    Hi Kishan,
    Thank you for your reply. What do you mean check the length of the
    variable? And Also, what about for others that instead of displaying
    one space below, it shows one space above? like:
                 5000
    Enervon                1,000
    The quantity 5000 must be in line with Enervon and 1,000. Thank you again!

Maybe you are looking for