How can i encrypt an ddecrypt a string using java

hai,
can anybody know how to encrypt and decrypt a string using java..
please if anybody help me with a small example and with code
thanks
ravi chandra

hi,
of course there are better ways to crypt your code, but the following 2 functions do their job....
as far as i know java has an own api for crypting stuff.
private String GetEncryptedString(String aCryptedString)
String result = "";
String str = aCryptedString;
int[] asciiArray = new int[str.length()];
for(int i = 0; i < asciiArray.length; i++)
asciiArray[i] = (int)str.charAt(i);
char tempChar = (char)(asciiArray[i]+3);
result = result+tempChar;
return result;
private String GetDecryptedString(String aString)
String result = "";
String str = aString;
int[] asciiArray = new int[str.length()];
for(int i = 0; i < asciiArray.length; i++)
asciiArray[i] = (int)str.charAt(i);
char tempChar = (char)(asciiArray[i]-3);
result = result+tempChar;
return result;
andi

Similar Messages

  • How can we get requester's user id using java code

    Hi,
    How can we get requester's user id using java code?
    eg: If i had logged in as xelsysadm and request a resource for user uid101 on the userid field it should display uid101 and not xelsysadm.
    also,
    I have a resoure "A" which on revoking should also revoke resources B and C. How can it be done. Resource A, B, and C are 3 different resource objects.
    ==Thanks,
    doki

    Ok, so there is a way, but it's not available during submission. You can use the findRequests api. From the result set, get the "Requests.Consolidated Data Value" value. In this information, you will get an xml formatted data. It provides the list of users on the request on the left side after submission. After the request is completed, this value is available. Upon completion, you could get the request information, get this value, and parse the information for user ids.
    In the same adapter, use the following API:
    formIntf.setObjectFormData(objInstanceKey, formHash)
    The formHash is a hashtable containing the field name on your object form, and the values you wish to populate it with. You could create a textarea box on your object form and populate the userids for who the request is for.
    However, this makes absolutely 0 sense. When you get a request, the list of userids are listed right there on the request.
    -Kevin

  • How can I encrypt/decrypt data in Forms using a specified Package?

    Hi All,
    I have searched in the Internet for ecnrypting/decrypting data in Forms.
    That is when I want to query the data outside the Form Application it will be encypted, otherwise if I want to query it in the form application it will be dycrypted
    I found this package:
    CREATE OR REPLACE PACKAGE Encrypt_pkg AS
    FUNCTION encrypt (p_text IN VARCHAR2) RETURN RAW;
    FUNCTION decrypt (p_raw IN RAW) RETURN VARCHAR2;
    END Encrypt_pkg;
    CREATE OR REPLACE PACKAGE BODY Encrypt_pkg AS
    -- All VARCHAR2 inputs are padded to multiples of 8 charaters,
    -- with the encryption key also being a multiple of 8 charaters.
    -- The encryption key and padding characters can be altered to suit.
    g_key RAW(32767) := UTL_RAW.cast_to_raw('12345678');
    g_pad_chr VARCHAR2(1) := '';
    PROCEDURE padstring (p_text IN OUT VARCHAR2);
    FUNCTION encrypt (p_text IN VARCHAR2) RETURN RAW IS
    l_text VARCHAR2(32767) := p_text;
    l_encrypted RAW(32767);
    BEGIN
    padstring(l_text);
    DBMS_OBFUSCATION_TOOLKIT.desencrypt(input => UTL_RAW.cast_to_raw(l_text),
    key => g_key,
    encrypted_data => l_encrypted);
    RETURN l_encrypted;
    END;
    FUNCTION decrypt (p_raw IN RAW) RETURN VARCHAR2 IS
    l_decrypted VARCHAR2(32767);
    BEGIN
    DBMS_OBFUSCATION_TOOLKIT.desdecrypt(input => p_raw,
    key => g_key,
    decrypted_data => l_decrypted);
    RETURN RTrim(UTL_RAW.cast_to_varchar2(l_decrypted), g_pad_chr);
    END;
    PROCEDURE padstring (p_text IN OUT VARCHAR2) IS
    l_units NUMBER;
    BEGIN
    IF LENGTH(p_text) MOD 8 > 0 THEN
    l_units := TRUNC(LENGTH(p_text)/8) + 1;
    p_text := RPAD(p_text, l_units * 8, g_pad_chr);
    END IF;
    END;
    END Encrypt_pkg;
    ** Now How can I use this package to encrypt/decrypt data in the form as I said Plz???

    <p>Read this article and go to chapter 2.3.2.</p>Inserts, Update and Delete orders are managed by a stored procedure. In the sample dialog, the Select is handled by the emp_pkg.emp_query() stored function:
      PROCEDURE emp_query(emp_data IN OUT emptab) IS
        ii NUMBER;
        CURSOR empselect IS
          SELECT empno, ename, job, sal, comm FROM emp
           ORDER BY ename ;
      BEGIN
        OPEN empselect;
        ii := 1;
        LOOP
          FETCH empselect INTO
            emp_data( ii ).empno,
            emp_data( ii ).ename,
            emp_data( ii ).job,
            emp_data( ii ).sal,
            emp_data( ii ).comm;
          EXIT WHEN empselect%NOTFOUND;
          ii := ii + 1;
        END LOOP;
      END emp_query;In your case, all you have to do is th use your decrypt() function in the cursor definition:
        CURSOR empselect IS
          SELECT decrypt(empno), decrypt(ename), decrypt(job), decrypt(sal), comm FROM emp
           ORDER BY ename ;
    ...For Insert and Update events, use the crypt() function in the related stored procedures.
      PROCEDURE emp_insert2(t IN emptab) IS
      BEGIN
        FOR i IN t.first..t.last LOOP
         INSERT INTO emp (empno, ename, job, sal, comm)
         VALUES(crypt(t(i).empno), crypt(t(i).ename), crypt(t(i).job), crypt(t(i).sal, t(i).comm));
         END LOOP ;
      END emp_insert2;Idem for the Update procedure.
    Francois

  • How can I authenticate to a XI server using java via SOAP (SAAJ)

    Hi everybody!
    I need to connect (SOAP) to a XI server using JAVA
    I'm using SAAJ api.The problem is XI server need authentication but I can't found the way to do it! this is a part of code
    SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnFactory.createConnection();
    URL destination = new URL("https://host:port");
    SOAPMessage reply = connection.call(message, destination);
    (message is the XML code)
    but the application has the following error:
    com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection post
    GRAVE: SAAJ0009: Fallo en el envío del mensaje
    I think, maybe is a authentication problem, because the XI server needs it. But I don't have idea how can I send the user and pass
    Any IDea???? please
    the libraries are ok imported, I use netweaver to develop-
    thanks in advantage

    hi Leslie,
    there are only a few of these errors,
    you can try this:
    http://www.oxygenxml.com/forum/ftopic1103.html&sid=0abee8c719481a3dd783ff7d5cd84105
    are you sure your URL is accessible from your location?
    you may also check:
    http://www.google.pl/search?hl=pl&q=HttpSOAPConnectionpostSAAJ0009%3A&lr=
    Regards,
    michal

  • How can i turn off the computer remotely using java?

    is it possible to use a java code for turning off the computer remotely by other computer in LAN?
    or if it is not possible how can i achieved that goal?
    thanx

    bd0 wrote:
    Well, if you're running linux you could use Runtime.getRuntime().exec() to execute 'halt -p', if the process was being run as root. Not terribly elegant but I suppose it would work. Although I wouldn't want an unattended process running as root.Yes, this is how you can do it, but on Windows machines as well. I'll go into pseudocode:
    App1: Server (running on every lab machine)
    open server socket on port X
    wait for connection
    verify connection is yourself so that not everyone can shut it down
    if not, wait for connection again
    if it is, run halt for linux or shutdown for windowsApp2: Client (running on just your computer)
    open a socket to each machine running the server app (or you could use multicasting)
    validate yourself however you did that
    close socketThere are some implications of this though - unless your validation mechanism is decent, pretty much anyone can shut down anything they want. Also, if you don't check for a logged-in user, you may destroy someone's work. Just keep those in mind.
    Also, if it is a Windows setting, there are usually better ways to do this - a well-managed windows network has built-in functionality to shut down computers remotely.
    Edited by: sprizor on Jun 22, 2008 10:59 AM

  • How can i access gmail's smtp server using java mail api

    i m using java mail api to access gmails pop and smtp service to receive and send mail from ur gmail account. I m able to access gmails pop server using the ssl and port 995 , but i can not use its smtp server to which i m connecting using ssl on 465 port. It requires authentication code.
    if anybody can help me in this regard i m thnkful to him/her.
    thnks in advance.
    jogin desai

    Here's an example of using SSL + Authentication
    http://onesearch.sun.com/search/onesearch/index.jsp?qt=ssl+authentication&subCat=siteforumid%3Ajava43&site=dev&dftab=siteforumid%3Ajava43&chooseCat=javaall&col=developer-forums

  • How can i get the HTTP header info using Java

    Hi,
    I kinda need to extract the HTTP header info from a page that i goto through a URL objecrt and socket. Java.
    Can someone please help me.. thanks!!!!
    System.out.println("Enter URL : ");
    String getAdd; // The URL that the crawler begins at.
    // Manually take in URL
    Scanner sc = new Scanner(System.in);
    getAdd = sc.nextLine();
    URL myURLobj = new URL(getAdd);
    String hostName = myURLobj.getHost();
              Socket s = new Socket(hostName, 80);

    URL url = new URL(getAdd);HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    Map<String, List<String>> headerFields = conn.getHeaderFields();

  • How can i encrypt "String" which present a Password

    i have a String which present password, how can i encrypt the password while i save it to an XML file and how i decipher the password when i load it from the XML file.
    Thanks

    You don't generally encrypt passwords. You simply hash them. There should rarely, if ever, be a reason to decrypt a password.
    http://java.sun.com/j2se/1.4.2/docs/guide/security/CryptoSpec.html
    http://java.sun.com/j2se/1.4.2/docs/guide/security/jce/JCERefGuide.html

  • How can I encrypt my data links between switch uplink ports ? I'm unable to use "cts Manual" command in C3560X switch.suggest me

    How can I encrypt my data uplinks between switch trunk ports ? I'm unable to use "cts Manual" command in C3560X switch.suggest me as I want to encrypt my switch-to-switch link with Cisco TrustSec.

    Hi 
    Login to switch & go to interface..
    There you can give tags.. (ISL & DONT1Q)
    Command switch-port mode trunk
    Switch-port trunk encapsulation ssl or dot1Q

  • How can I copy and forward a string of text messages from a Iphone 5s to an email address

    How can I copy and forward a string of text messages from an IPhone 5S to an Email address?

    You can find my blog post on the same.
    http://www.pointtobenoted.com/blog/technology/mobile/how-to-copy-messages-from-i message/
    The 6 steps process is listed step by step.
    Hope this helps.
    http://www.pointtobenoted.com/

  • How can we get  tag of XML file using SAX

    Hi ,
    I'm parsing one SAX parser , I'have almost done this parsing. i have faced problem for one case, i'e how can we get tag from XML file using SAX parser?
    XML file is
    <DFProperties>
    <AccessType>
    <Get/>
    </AccessType> <Description>
    gdhhd
    </Description>
    <DFFormat>
    <chr/>
    </DFFormat>
    <Scope>
    <Permanent/>
    </Scope>
    <DFTitle>gsgd</DFTitle>
    <DFType>
    <MIME>text/plain</MIME>
    </DFType>
    </DFProperties>
    I want out like GET and Permanent... means this one tag which is present inside of another tag.
    Handler class like
    public void startElement(String namespaceURI, String localName,
                   String qName, Attributes atts) throws SAXException {
    if(_ACCESSTYPE.equals(localName)){
                   accessTypeElement=ACCESSTYPE;
    public void characters(char[] ch, int start, int length)
                   throws SAXException {
    if (_ACCESSTYPE.equals(_accessTypeElement)) {
                   String strValue = new String(ch, start, length);
                   System.out.println("Accestype-----------------------------> " + strValue);
                   //System.out.println(" " + strValue);
    public void endElement(String namespaceURI, String localName, String qName)
                   throws SAXException {
    if (_ACCESSTYPE.equals(localName)) {
                   _accessTypeElement = "";
    . please any body help me

    Hi ,
    I have one problem,Please help me.
    1. How can I'll identify where exactly my Node is ended,means how how can we find corresponding nodename? in partcular place
    <Node> .............starttag1
    <NodeName>Test</NodeName>
    <Node>................starttag2
    <nodeName>test1</NodeName>
    </Node>..................endtag2
    <Node>.....................starttag3
    <NodeName><NodeName>
    <Node> .........................starttag4
    <NodeName>test4</NodeName>
    </Node>.......enddtag4
    </Node>...........end tag3
    </Node>............endtag1
    my code is below
    private final String _NODENAME = "NodeName";
    private final String _NODE = "Node";
    private String _nodeElement = "";
         private String _NodeNameElement = "";
    public void startElement(String namespaceURI, String localName,
                   String qName, Attributes atts) throws SAXException {
    if (_NODENAME.equals(localName)) {
                   NodeNameElement = NODENAME;
    if(_NODE.equals(localName)){
         System.out.println("start");
         if (_NODENAME.equals(localName)) {
                   NodeNameElement = NODENAME;
    public void characters(char[] ch, int start, int length)
                   throws SAXException {
    if (_NODENAME.equals(_NodeNameElement)) {
                   String strValue = new String(ch, start, length);
                   String sttt=strValue;
                   System.out.println("NODENAME: ************* " + strValue);
    if(_NODE.equals(_nodeElement)){
                   if (_NODENAME.equals(_NodeNameElement)) {
                        String strValue = new String(ch, start, length);
                        String sttt=strValue;
                        System.out.println("nodevalue********** " + strValue);
    public void endElement(String namespaceURI, String localName, String qName)
                   throws SAXException {
    if (_NODENAME.equals(localName)) {
                   _NodeNameElement = "";
    if(_NODE.equals(localName)){
                   System.out.println("NODENAME: %%%%%%%%%");
    please help me. How can I figure node ending for particular nodename

  • How to search for upper/lower case using string using JAVA!!!?

    -I am trying to write a program that will examine each letter in the string and count how many time the upper-case letter 'E' appears, and how many times the lower-case letter 'e' appears.
    -I also have to use a JOptionPane.showMessageDialog() to tell the user how many upper and lower case e's were in the string.
    -This will be repeated until the user types the word "Stop". 
    please help if you can
    what i have so far:
    [code]
    public class Project0 {
    public static void main(String[] args) {
      String[] uppercase = {'E'};
      String[] lowercase = {'e'};
      String isOrIsNot, inputWord;
      while (true) {
       // This line asks the user for input by popping out a single window
       // with text input
       inputWord = JOptionPane.showInputDialog(null, "Please enter a sentence");
       if ( inputWord.equals("stop") )
        System.exit(0);
       // if the inputWord is contained within uppercase or
       // lowercase return true
       if (wordIsThere(inputWord, lowercase))
        isOrIsNot = "Number of lower case e's: ";
       if (wordIsThere(inputword, uppercase))
         isOrIsNot = "number of upper case e's: ";
       // Output to a JOptionPane window whether the word is on the list or not
       JOptionPane.showMessageDialog(null, "The word " + inputWord + " " + isOrIsNot + " on the list.");
    } //main
    public static boolean wordIsThere(String findMe, String[] theList) {
      for (int i=0; i<theList.length; ++i) {
       if (findMe.equals(theList[i])) return true;
      return false;
    } // wordIsThere
    } // class Lab4Program1
    [/code]

    So what is your question? Do you get any errors? If so, post them. What doesn't work?
    And crossposted: how to search for upper/lower case using string using JAVA!!!?

  • How can i execute excelsheet without giving path in java

    Hi,
    How can i execute excelsheet without giving path in java, through this code, you can open the notepad but
    I want whereever the excel is installed in your machine , fine and open excelsheet without given absolute path.
    class ExecuteCommand{
    public static void main(String d[]){
         Runtime r = Runtime.getRuntime();
         Process p= null;
         try{
         p = r.exec("notepad");
              catch(Exception e){
                   System.out.println("error");
    If you know please send me your idea and code samples.
    regards
    Mohan kumar

    just execute the exelfile with the Windows "start" command:
    Runtime.exec("cmd /c start "+excelFileName);But this requires that Excel is the default application for the Excel file type (*.xls). You can test this by simply typing "start myTestExcel.xls" in a dos box.

  • How can i return object from oracle in my java code using pl/sql procedure?

    How can i return object from oracle in my java code using pl/sql procedure?
    And How can i returned varios rows fron a pl/sql store procedure
    please send me a example....
    Thank you
    null

    yes, i do
    But i can't run this examples...
    my problem is that i want recive a object from a PL/SQL
    //procedure callObject(miObj out MyObject)
    in my java code
    public static EmployeeObj callObject(Connection lv_con,
    String pv_idEmp)
    EmployeeObj ret = new EmployeeObj();
    try
    CallableStatement cstmt =
    lv_con.prepareCall("{call admin.callObject(?)}");
    cstmt.registerOutParameter(1, OracleTypes.STRUCT); // line ocurr wrong
    //registerOutParameter(int parameterIndex, int sqlType,String sql_name)
    cstmt.execute();
    ret = (EmployeeObj) cstmt.getObject(1);
    }//try
    catch (SQLException ex)
    System.out.println("error SQL");
    System.out.println ("\n*** SQLException caught ***\n");
    while (ex != null)
    System.out.println ("SQLState: " + ex.getSQLState ());
    System.out.println ("Message: " + ex.getMessage ());
    System.out.println ("Vendor: " + ex.getErrorCode ());
    ex = ex.getNextException ();
    System.out.println ("");
    catch (java.lang.Exception ex)
    System.out.println("error Lenguaje");
    return ret;
    Do you have any idea?

  • How can I determine the cipher bit strength used by MY os X?

    How can I determine the cipher bit strength used by MY OS X?  Using Lion now?

    CT:
    Not Filvault, but the regular cryptographic use as built into OS X.  For example 1Password uses the algorithm in the OS X's Linux.  How many bits (i.e. 50, 128, 256...) does it use and what algorithm (DES, AES...)
    Linc
    As per reply to CT?
    Like so:
    http://osxdaily.com/2012/01/30/encrypt-and-decrypt-files-with-openssl/
    What is the strength used?

Maybe you are looking for

  • Unable to connect SQL server 2005 databse with JSF applications !

    Hello guys! Help me out to connect SQL server 2005 Databse with JSF applications using JDBC-ODBC bridge. I'm working with Netbeans 6.1 IDE. I tried for the basic applications but instead got this error: "unable to deploy jdbc drivers to the <project>

  • AirTunes compatibility with Front Row

    In the AirPort Express FAQ, it says: Question: Can I use other applications, like QuickTime or Windows Media Player, to send sound to AirPort Express via AirTunes? Answer: At this time Apple only supports sending one AirTunes stream to AirPort Expres

  • Photos on my IPAD to my PC and back to my PC

    I had transfered all my photos to my IPAD from my desktop as kind of a back-up.  If I were to lose my desktop hard drive, can I retrieve my photos from my IPAD back to my PC.  If so, what would I do?  thanks

  • JavaScript to format SSN

    Hello, Im using Apex 4.1, Oracle 11g. I have a simple page, and the requirement is to automatically format a SSN field to include dashes (-) should the customer only enter in all numbers. I have written a javascript function to handle this, but no ma

  • Is it possible to automatically unwrap all instancies of a element in Frame 7.2 ?

    Hi all, Is it possible to automatically unwrap all instancies of a element called "Table Cell" in Frame 7.2 ? I can unwrap manually but there are over 400 instanticies!! No longer needed due to a template update. Thanks in advancce