Friends help urgent :encryption & decryption

hi all
can anyone please tell me where i can download
separate encrpytion and decryption codes
in java.
please help

Hi swaroopha,
I hope that you need encryption and decryption code for Security purpose. Here with I am sending the sample code which does encryption and decryption in the same program.
For this you have to download JCE
from www.java.sun.com/jce.
Here is the sample program:
import java.io.*;
import java.security.*;
import javax.crypto.*;
import sun.misc.*;
public class SecretWriting{
public static void main(String args[]) throws Exception{
if(args.length<2)
System.out.println("Usage : SecretWriting -e|-d text");
return;
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Key key;
try{
ObjectInputStream in=new ObjectInputStream(new FileInputStream("des.key"));
key=(Key)in.readObject();
in.close();
catch(FileNotFoundException fnfe)
KeyGenerator generator= KeyGenerator.getInstance("DES");
generator.init(new SecureRandom() );
key=generator.generateKey();
ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("des.key"));
out.writeObject(key);
out.close();
Cipher cipher=Cipher.getInstance("DES/ECB/PKCS5Padding");
if(args[0].indexOf("e") !=-1)
cipher.init(Cipher.ENCRYPT_MODE,key);
String amalgam=args[1];
for(int i=2;i<args.length;i++)
amalgam+=" "+args;
byte[] stringBytes=amalgam.getBytes("UTF8");
byte[] raw=cipher.doFinal(stringBytes);
BASE64Encoder encoder = new BASE64Encoder();
String base64 = encoder.encode(raw);
System.out.println(base64);
else if(args[0].indexOf("d")!=-1)
cipher.init(Cipher.DECRYPT_MODE,key);
BASE64Decoder decoder = new BASE64Decoder();
byte[] raw = decoder.decodeBuffer(args[1]);
byte[] stringBytes = cipher.doFinal(raw);
String result = new String(stringBytes,"UTF8");
System.out.println(result);
I hope this will help you out.
Thanks
Bakrudeen
Technical Support Engineer
Sun MicroSystems Inc, India

Similar Messages

  • Help ! Need PCI Encryption/Decryption Controller Driver for New HP 355 G2 (AMD) w/Win 7 Pro 64 Bit

    Just rebuilt new HP 355 G2 to Win 7 64 bit.  The ONLY driver I can not locate or get to work is the PCI Encryption/Decryption Controller. I installed all latest drivers for this model/OS from both HP and AMD sites still no luck. AMD autodetect utility and Catalyst software installed all other drivers successfully except this one and when completes says all drivers, including chipset, are installed successfully and current.
    I am at a complete loss where to get this driver from a OEM site, can you help ?
    Device ID's:
    PCI\VEN_1022&DEV_1537&SUBSYS_15371022&REV_00
    PCI\VEN_1022&DEV_1537&SUBSYS_15371022
    PCI\VEN_1022&DEV_1537&CC_108000
    PCI\VEN_1022&DEV_1537&CC_1080
    Thanks !!!
    This question was solved.
    View Solution.

    Hi:
    You need to run this driver and then manually install it.
    http://h20565.www2.hp.com/hpsc/swd/public/detail?swItemId=vc_133833_1
    To manually install the driver go to the device manager and click on the PCI Encryption/Decryption Controller needing the driver.
    Click on the driver tab.  Click on Update Driver.
    Select the Browse my computer for driver software option, and browse to the driver folder that was created when you ran the file.
    That folder will be located in C:\SWSetup\sp66974.
    Make sure the Include Subfolders box is checked, and the driver should install.
    Then reboot.

  • Can any body help in doing Encryption & Decryption process????????

    Hi,
      I am developing one file-file interface for sending sensitive data from one file system to another file system. As this is sensitive data, i need to decrypt this data ( file i am picking from source system is already encrypted in source directory ) and i need to send it to target system. i found some alternatives like module development and pgp encryption. I am not that much proficient to develop module and i looking at other alternative like pgp. Is PGP is free software?? how can i install and how can i call from my sender adapter?? Please Help.
         Thanks
    madhusudhan.

    Hi madhusudan
    refer the below link
    <u>Encryption & Decryption of data using ABAP</u>
    /people/kathirvel.balakrishnan2/blog/2006/11/21/encryption-decryption-of-data-using-abap
    <u>JAVA API's for PGP Encryption/Decryption</u>
    http://www.bouncycastle.org/documentation.html
    you got some examples
    Check this document on how to do message level security:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d024ca8e-e76e-2910-c183-8ea4ba681c51
    Deploying the SAP Java Cryptographic Toolkit
    http://help.sap.com/saphelp_nw04/helpdata/en/8d/cb71b8046e6e469bf3dd283104e65b/frameset.htm
    Key Storage Service
    http://help.sap.com/saphelp_nw04/helpdata/en/e9/a1dd44d2c83c43afb5ec8a4292f3e0/frameset.htm
    If these things are already done then u need juz few modification in the adapter configuration.
    In FTP Connection Parameters -> command line -> FTPS (Control and Data connection)
    You can also go through the blogs
    Encryption(SSL)
    /people/varadharajan.krishnasamy/blog/2007/05/11/how-to-use-digital-certificates-for-signing-encrypting-messages-in-xi
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/b2e7020d-0d01-0010-269c-a98d3fb5d16c
    Examples for Using Digital Signatures
    http://help.sap.com/saphelp_nw04s/helpdata/en/a4/d0201854fb6a4cb9545892b49d4851/frameset.htm
    How to configure Message level security
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/b2e7020d-0d01-0010-269c-a98d3fb5d16c
    document on encryption in adpaters
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/482aae19-0301-0010-3485-8efd618818d0
    Encrypt and Decrypt Data
    <b>Pls reward if useful</b>

  • Help for a newbie on encryption/decryption

    I want to start with a text file.
    Read in a line of ascii characters, encrypt it using some algorithm and output it as a new set of ascii characters.
    What algorithm should I use?

    thanks a lot. I got the encryption/decryption working pretty easily.
    However, I ran into problem when I got to storing keys:
    I stored it fine with this code
              try {
                   KeyGenerator keyGen = KeyGenerator.getInstance("DES");
                   desKey = keyGen.generateKey();
                   cipher = Cipher.getInstance("DES");
                   KeyStore keyStore = KeyStore.getInstance("JKS");
                   String password = "lemein";
                   char passwd[] = password.toCharArray();
                   keyStore.load(null, passwd); //initialize keyStore
                   Certificate[] chain = new Certificate[1];
                   String alias = "test";
                   keyStore.setKeyEntry(alias, desKey, passwd, null);
                   String fileName = "data/gkey.txt";
                   FileOutputStream f = new FileOutputStream(fileName);
                   keyStore.store(f, passwd); // <----------exception happens here
              } catch (Exception e)
              {     e.printStackTrace();
    I got problem when I retrieve it with this code
              KeyGenerator kg = null;
              Key key = null;
              cipher = null;
              Security.addProvider(new com.sun.crypto.provider.SunJCE());
              byte[] result = null;
              try {
                   KeyStore keyStore = KeyStore.getInstance("JKS");
                   keyStore.load(new FileInputStream("data/gkey.txt"), "lemein".toCharArray());
                   key = keyStore.getKey("test", "lemein".toCharArray());
                   cipher = Cipher.getInstance("DES");
                   byte[] data = "Hello World!".getBytes();
                   System.out.println("Original data : " + new String(data));
                   cipher.init(Cipher.ENCRYPT_MODE, key);
                   result = cipher.doFinal(data);
                   System.out.println("Encrypted data: " + new String(result));
              } catch (Exception e) {
                   e.printStackTrace();
    I get the error:
    java.security.UnrecoverableKeyException: DerInputStream.getLength(): lengthTag=75, too big.
         at sun.security.provider.KeyProtector.recover(Unknown Source)
         at sun.security.provider.JavaKeyStore.engineGetKey(Unknown Source)
         at java.security.KeyStore.getKey(Unknown Source)
    Any idea what the problem is?
    Thanks

  • Error in running encryption/decryption using DES in Websphere Dev't Client

    Hello!
    I have a code used to encrypt / decrypt a string (password). I have already tested it using Netbeans and it is working. But when I tried to add the java code to an existing web project using Websphere Development Client,, javax.crypto.* is not recognized. Then I imported JCE.jar.
    The java code contains no errors then, but when I started to run the project, it gives an Error 500. And below is the Console's error message:
    E SRVE0026E: [Servlet Error]-[javax.crypto.spec.PBEKeySpec: method <init>&#40;[C[BI&#41;V not found]: java.lang.NoSuchMethodError: javax.crypto.spec.PBEKeySpec: method <init>([C[BI)V not found[/b]
    Have I missed something to add? Or other things that I should do upon importing this jar file?
    Please help.
    Advance thanks for your reply.
    misyel

    I dont know what version of Java that my Websphere's using. But I am very sure that it is outdated. I am using Websphere 5.0. For Netbeans, it is JDK1.5.
    I imported the JCE from JDK 1.5 on Websphere.
    I think the code works perfectly fine. Actually it was my friend's code for encryption but they are using Eclipse for development (almost the same from Websphere but somehow different from it.)
    My idea is that I cant match the versions of the jarfiles used in my project. As much as I wanted to change the imported jar files, I couldn't for when I replaced the existing jar files, more and more errors occur.
    can we have any alternative ways of importing the jar files? or is there any other code that might help that will not use the JCE.jar?
    I really appreciate your response. thanks
    misyel

  • Encryption/Decryption  failure for pdf and MSWord files

    Hi,
    Is there anybody to help me to find out what is wrong with my class (listing below)? I am sucessfuly using this class to encrypt and decrypt txt, html files but for unknown reasons I am unable to use it for e.g. pdf files. The encrypion somehow works but any atempt to decrypt is a failure.
    /* This class accepts an input file, encrypts/decrypts it using DES algorithm and
    writes the encrypted/decrypted output to an output file. DES is used in Cipher
    Block Chaining mode with PKCS5Padding padding scheme. Note that DES is a symmetric
    block cipher that uses 64-bit keys for encryption. A password of length no less
    than 8 is to be passed to the encryptFile/ decryptFile methods. This password is
    used to generate the encryption key. All exception handling is to be done by
    calling methods. These exceptions are thrown by encryptFile/ decryptFile methods.
    The input buffer is 64 bytes, 8 times the key size.
    import java.io.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import java.security.*;
    import java.security.spec.*;
    public class Crypto
    public Crypto(FileInputStream inStream_, FileOutputStream outStream_)
    fInputStream_ = inStream_;
    fOutputStream_ = outStream_;
    public void encryptFile(String password_) throws InvalidKeySpecException, InvalidKeyException,
    InvalidAlgorithmParameterException, IllegalStateException, IOException, Exception
    DataOutputStream dataOutStream_ = new DataOutputStream(fOutputStream_);
    // key generation
    SecretKey encryptKey_ = createEncryptionKey(password_);
    // Cipher initialization
    Cipher cipher_= Cipher.getInstance(cipherType);
    cipher_.init(Cipher.ENCRYPT_MODE, encryptKey_);
    // write initialization vector to output
    byte[] initializationVector_ = cipher_.getIV();
    dataOutStream_.writeInt(initializationVector_.length);
    dataOutStream_.write(initializationVector_);
    // start reading from input and writing encrypted data to output
    while (true) {
    inputLength_ = fInputStream_.read(input_);
    if (inputLength_ ==-1) break;
    byte[] output_ = cipher_.update(input_, inputOffset_, inputLength_);
    if (output_ != null)
    dataOutStream_.write(output_);
    // finalize encryption and wrap up
    byte[] output_ = cipher_.doFinal();
    if (output_ != null)
    dataOutStream_.write(output_);
    fInputStream_.close();
    dataOutStream_.flush();
    dataOutStream_.close();
    public void decryptFile(String password_) throws IllegalStateException, IOException, Exception
    DataInputStream dataInStream_ = new DataInputStream(fInputStream_);
    // key generation
    SecretKey encryptKey_ = createEncryptionKey(password_);
    // read initialization vector from input
    int ivSize_ = dataInStream_.readInt();
    byte[] initializationVector_ = new byte[ivSize_];
    dataInStream_.readFully(initializationVector_);
    IvParameterSpec ivParamSpec_= new IvParameterSpec(initializationVector_);
    // Cipher initialization
    Cipher cipher_= Cipher.getInstance("DES/CBC/PKCS5Padding");
    cipher_.init(Cipher.DECRYPT_MODE, encryptKey_, ivParamSpec_);
    // start reading from input and writing decrypted data to output
    while (true) {
    inputLength_ = fInputStream_.read(input_);
    if (inputLength_ ==-1) break;
    byte[] output_ = cipher_.update(input_, inputOffset_, inputLength_);
    if (output_ != null)
    fOutputStream_.write(output_);
    // finalize decryption and wrap up
    byte[] output_ = cipher_.doFinal();
    if (output_ != null)
    fOutputStream_.write(output_);
    fInputStream_.close();
    fOutputStream_.flush();
    fOutputStream_.close();
    // the following method creates the encryption key using the supplied password
    private SecretKey createEncryptionKey(String passwd_) throws InvalidKeySpecException,
    InvalidKeyException, NoSuchAlgorithmException
    byte[] encryptionKeyData_ = passwd_.getBytes();
    DESKeySpec encryptionKeySpec_ = new DESKeySpec(encryptionKeyData_);
    SecretKeyFactory keyFactory_ = SecretKeyFactory.getInstance(algorithm_);
    SecretKey encryptionKey_ = keyFactory_.generateSecret(encryptionKeySpec_);
    return encryptionKey_;
    private FileInputStream fInputStream_;
    private FileOutputStream fOutputStream_;
    private final String algorithm_= "DES";
    private final String cipherType= "DES/CBC/PKCS5Padding";
    private byte[] input_ = new byte[64]; // The input buffer size is 64
    private int inputLength_;
    private final int inputOffset_= 0;
    }

    Please can u give me refined code for me///
    at [email protected]
    Hi,
    I found at least one thing wrong. In the decrypt
    method you are reading from 'fInputStream_' rather
    than 'dataInStream'.
    Worked for me on MSWord after changing this!
    Roger
    // start reading from input and writing decrypted
    ted data to output
    while (true) {
    inputLength_ = fInputStream_.read(input_);
    if (inputLength_ ==-1) break;
    byte[] output_ = cipher_.update(input_,
    input_, inputOffset_, inputLength_);
    if (output_ != null)
    fOutputStream_.write(output_);

  • How to resolve bug RC4 encrypt-decrypt on iPAD with AIR15 only

    Hi everybody,
    I have some trouble with AIR15 only, In the past, I created a small game on iPad It could send or receive messge from server. I used lib as3crypto.swc encrypt or decrypt message (RC4). But when I upgrade to AIR15 encrypt-decrypt cannot work ( Another thing about this crash is that it only happens with a release (adhoc or appstore) build but NOT with a debug build). I check so many time but i don't know what is problem here.
    Please help me, thanks so much any advice.
    P/S: My game have many swf files (code and resource). I must combine multiple SWF files into one.
    Class RC4.as
    import com.hurlant.crypto.prng.ARC4;
    import com.hurlant.util.Base64;
    import com.hurlant.util.Hex;
    import flash.utils.ByteArray;
    public class RC4
      private static const key:String = "keytest";
      private static var byteKeys:ByteArray = Hex.toArray(Hex.fromString(key));
      private static var rc4:ARC4 = new ARC4();
      public static function encrypt(clearText:String):String
      var byteText:ByteArray = Hex.toArray(Hex.fromString(clearText));
      rc4.init(byteKeys);
      rc4.encrypt(byteText);
      return Base64.encodeByteArray(byteText);
    public static function decrypt(encryptedText:String):String
      var byteText:ByteArray = Base64.decodeToByteArray(encryptedText);
      rc4.init(byteKeys);
      rc4.decrypt(byteText);
      return Hex.toString(Hex.fromArray(byteText));

    Sorry, exact message is "this movie could not be played".
    There are hundreds of posts about this message but no one states a clear solution to the problem.
    Your help will be much appreciated.
    Thank you.

  • Encrypt/decrypt AES 256, vorsalt error

    Hiyas.
    So I'm trying to get encrypt/decrypt to work for AES 256, with both 32byte key and 32byte IVorSalt. (Yup-new java security files v6 installed)
    'IF' I 32byte key but dont use a IV at all, I get a nice looking AES 256 result. (I can tell it's AES 256 by looking the length of the encrypted string)
    'IF' I use a 32byte key and 16bit salt, I get a AES 128 result (I know- as per docs theyre both s'posed to the same size, but the docs are wrong).
    But when i switch to using both a 32byte key AND a 32byte salt I get the error below.
    An error occurred while trying to encrypt or decrypt your input string: Bad parameters: invalid IvParameterSpec: com.rsa.jsafe.crypto.JSAFE_IVException: Invalid IV length. Should be 16.
    Has anyone 'EVER' gotten encrypt to work for them using AES 256 32byte key and 32byte salt? Is this a bug in CF? Or Java? Or I am doing something wrong?
    <!--- ////////////////////////////////////////////////////////////////////////// Here's the Code ///////////////////////////////////////////////////////////////////////// --->
    <cfset theAlgorithm  = "Rijndael/CBC/PKCS5Padding" />
    <cfset gKey = "hzj+1o52d9N04JRsj3vTu09Q8jcX+fNmeyQZSDlZA5w="><!--- these 2 are the same --->
    <!---<cfset gKey = ToBase64(BinaryDecode("8738fed68e7677d374e0946c8f7bd3bb4f50f23717f9f3667b2419483959039c", "Hex"))>--->
    <cfset theIV    = BinaryDecode("7fe8585328e9ac7b7fe8585328e9ac7b7fe8585328e9ac7b7fe8585328e9ac7b","hex")>
    <!---<cfset theIV128    = BinaryDecode("7fe8585328e9ac7b7fe8585328e9ac7b","hex")>--->
    <cffunction    name="DoEncrypt" access="public" returntype="string" hint="Fires when the application is first created.">
        <cfargument    name="szToEncrypt" type="string" required="true"/>
        <cfset secretkey = gKey>               
        <cfset szReturn=encrypt(szToEncrypt, secretkey, theAlgorithm, "Base64", theIV)>
        <cfreturn szReturn>
    </cffunction>   
    <cffunction    name="DoDecrypt" access="public" returntype="string" hint="Fires when the application is first created.">
        <cfargument    name="szToDecrypt" type="string" required="true"/>
        <cfset secretkey = gKey>   
        <cfset szReturn=decrypt(szToDecrypt, secretkey, theAlgorithm, "Base64",theIV)>       
        <cfreturn szReturn>
    </cffunction>
    <cfset szStart = form["toencrypt"]>
    <cfset szStart = "Test me!">
    <cfset szEnc = DoEncrypt(szStart)>
    <cfset szDec = DoDecrypt(szEnc)>
    <cfoutput>#szEnc# #szDec#</cfoutput>

    Hi edevmachine,
    This Bouncy Castle Encryption CFC supports Rijndael w/ 256-bit block size. (big thanks to Jason here and all who helped w/ that, btw!)
    Example:
    <cfscript>
      BouncyCastleCFC = new path.to.BouncyCastle();
      string = "ColdFusion Rocks!"; 
      key = binaryEncode(binaryDecode(generateSecretKey("Rijndael", 256), "base64"), "hex");//the CFC takes hex'd key
      ivSalt = binaryEncode(binaryDecode(generateSecretKey("Rijndael", 256), "base64"), "hex");//the CFC takes hex'd ivSalt
      encrypted = BouncyCastleCFC.doEncrypt(string, key, ivSalt);
      writeOutput(BouncyCastleCFC.doDecrypt(encrypted, key, ivSalt));
    </cfscript>
    Related links for anyone interested in adding 256-bit block size Rijndael support into ColdFusion:
    - An explanation of how to install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files into ColdFusion
    - An explanation of how to install the Bouncy Castle Crypto package into ColdFusion (near bottom, under the "Installing additional security providers" heading)
    - An explanation of how to connect the Bouncy Castle classes together
    - Bouncy Castle's doc for the Rijndael Engine
    And here is the full CFC as posted in the StackOverflow discussion:
    <cfcomponent displayname="Bounce Castle Encryption Component" hint="This provides bouncy castle encryption services" output="false">
    <cffunction name="createRijndaelBlockCipher" access="private">
        <cfargument name="key" type="string" required="true" >
        <cfargument name="ivSalt" type="string" required="true" >
        <cfargument name="bEncrypt" type="boolean" required="false" default="1">
        <cfargument name="blocksize" type="numeric" required="false" default=256>
        <cfscript>
        // Create a block cipher for Rijndael
        var cryptEngine = createObject("java", "org.bouncycastle.crypto.engines.RijndaelEngine").init(arguments.blocksize);
        // Create a Block Cipher in CBC mode
        var blockCipher = createObject("java", "org.bouncycastle.crypto.modes.CBCBlockCipher").init(cryptEngine);
        // Create Padding - Zero Byte Padding is apparently PHP compatible.
        var zbPadding = CreateObject('java', 'org.bouncycastle.crypto.paddings.ZeroBytePadding').init();
        // Create a JCE Cipher from the Block Cipher
        var cipher = createObject("java", "org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher").init(blockCipher,zbPadding);
        // Create the key params for the cipher    
        var binkey = binarydecode(arguments.key,"hex");
        var keyParams = createObject("java", "org.bouncycastle.crypto.params.KeyParameter").init(BinKey);
        var binIVSalt = Binarydecode(ivSalt,"hex");
        var ivParams = createObject("java", "org.bouncycastle.crypto.params.ParametersWithIV").init(keyParams, binIVSalt);
        cipher.init(javaCast("boolean",arguments.bEncrypt),ivParams);
        return cipher;
        </cfscript>
    </cffunction>
    <cffunction name="doEncrypt" access="public" returntype="string">
        <cfargument name="message" type="string" required="true">
        <cfargument name="key" type="string" required="true">
        <cfargument name="ivSalt" type="string" required="true">
        <cfscript>
        var cipher = createRijndaelBlockCipher(key=arguments.key,ivSalt=arguments.ivSalt);
        var byteMessage = arguments.message.getBytes();
        var outArray = getByteArray(cipher.getOutputSize(arrayLen(byteMessage)));
        var bufferLength = cipher.processBytes(byteMessage, 0, arrayLen(byteMessage), outArray, 0);
        var cipherText = cipher.doFinal(outArray,bufferLength);
        return toBase64(outArray);
        </cfscript>
    </cffunction>
    <cffunction name="doDecrypt" access="public" returntype="string">
        <cfargument name="message" type="string" required="true">
        <cfargument name="key" type="string" required="true">
        <cfargument name="ivSalt" type="string" required="true">
        <cfscript>
        var cipher = createRijndaelBlockCipher(key=arguments.key,ivSalt=arguments.ivSalt,bEncrypt=false);
        var byteMessage = toBinary(arguments.message);
        var outArray = getByteArray(cipher.getOutputSize(arrayLen(byteMessage)));
        var bufferLength = cipher.processBytes(byteMessage, 0, arrayLen(byteMessage), outArray, 0);
        var originalText = cipher.doFinal(outArray,bufferLength);
        return createObject("java", "java.lang.String").init(outArray);
        </cfscript>
    </cffunction>
    <cfscript>
    function getByteArray(someLength)
        byteClass = createObject("java", "java.lang.Byte").TYPE;
        return createObject("java","java.lang.reflect.Array").newInstance(byteClass, someLength);
    </cfscript>
    </cfcomponent>
    Thanks!,
    -Aaron

  • Encrypt/decrypt

    Hello!
    I have been trying to use this syntax for encrypting/decrypting BUT I get different values all the time even if I use the same String. I would be really glad if anyone could help me to tell me why. What I want to use this encrypt/decrypt/ is to make some info unreadable in my database but I want to be able to decrypt the info.
    -----------------------------syntax----------------------------------------------------------------------
    SecretKey key=null;
    try{
    key = KeyGenerator.getInstance("DES").generateKey();
    }catch(Exception e){}
    DesEncrypter d= new DesEncrypter(key);
    -----------------------------My cryptClass--------------------------------------------------------
    public class DesEncrypter {
    Cipher ecipher;
    Cipher dcipher;
    DesEncrypter(SecretKey key) {
    try {
    ecipher = Cipher.getInstance("DES");
    dcipher = Cipher.getInstance("DES");
    ecipher.init(Cipher.ENCRYPT_MODE, key);
    dcipher.init(Cipher.DECRYPT_MODE, key);
    } catch (javax.crypto.NoSuchPaddingException e) {
    } catch (java.security.NoSuchAlgorithmException e) {
    } catch (java.security.InvalidKeyException e) {
    public String encrypt(String str) {
    try {
    // Encode the string into bytes using utf-8
    byte[] utf8 = str.getBytes("UTF8");
    // Encrypt
    byte[] enc = ecipher.doFinal(utf8);
    // Encode bytes to base64 to get a string
    return new sun.misc.BASE64Encoder().encode(enc);
    } catch (javax.crypto.BadPaddingException e) {
    } catch (IllegalBlockSizeException e) {
    } catch (UnsupportedEncodingException e) {
    } catch (java.io.IOException e) {
    return null;
    public String decrypt(String str) {
    try {
    // Decode base64 to get bytes
    byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
    // Decrypt
    byte[] utf8 = dcipher.doFinal(dec);
    // Decode using utf-8
    return new String(utf8, "UTF8");
    } catch (javax.crypto.BadPaddingException e) {
    } catch (IllegalBlockSizeException e) {
    } catch (UnsupportedEncodingException e) {
    } catch (java.io.IOException e) {
    return null;
    thanks in advance!

    I don't understand caffeiene's answer but maybe it will help you. It seems to me that you need to encrypt and decrypt the same way across application sessions, etc. Therefore you will need to store your key outside of the application in a file on the server. So you'll have to use a key generator that will let you save the key to a file. That's about all the detail I can give you since I've never worked directly with cryptography. Obviously you'll need to make sure the server is behind a good firewall, or whatever other security measures you deem appropriate to protect the key. It seems unsecure, but you have to persist the key, because otherwise if the app server crashes then the data in the db will be inaccessible.

  • Encrypt/Decrypt data, multiple public keys using Bouncy castle api?

    Hi all.
    I need to implement encrypt/decrypt functionality of some data with many public keys using bouncy castle api and EnvelopedData class in java 1.4 SE.
    Could someone give me examples how to do it. I searched whole the internet and i could not find simple example.

    Hi thanks very much.
    I had a quick look at the examples. I will see if they could help me.
    Here is more specific what i want:
    Encrypt data with multiple public keys that are kept in .pkcs12 file.
    And decrypt the data using coresponding private key after that.
    I must use bouncy castle api for java 1.4 se.
    Best regards
    Edited by: menchev on Nov 13, 2008 8:26 AM

  • Encrypt/Decrypt BLOB

    Hello experts
    Can anyone help write a stored procedure that can encrypt/decrypt binary data.
    I want to pass in an ID and a key and have the procedure decrypt the data and return unencrypted binary data (serve straight to browser). Then a procedure to do the opposite, take some binary data, encrypt and store - then give me back the ID?
    I'm not sure about key management yet - your advice is appreciated
    Thanks for any help
    Matt

    Here's the retrieve code:
    create or replace package image_get
    as
    procedure gif( p_id in demo.id%type );
    end;
    create or replace package body image_get
    as
    procedure gif( p_id in demo.id%type )
    is
    l_lob blob;
    l_amt number default 30;
    l_off number default 1;
    l_raw raw(4096);
    begin
    select theBlob into l_lob
    from demo
    where id = p_id;
    -- make sure to change this for your type!
    owa_util.mime_header( 'image/gif' );
    begin
    loop
    dbms_lob.read( l_lob, l_amt, l_off, l_raw );
    -- it is vital to use htp.PRN to avoid
    -- spurious line feeds getting added to your
    -- document
    htp.prn( utl_raw.cast_to_varchar2( l_raw ) );
    l_off := l_off+l_amt;
    l_amt := 4096;
    end loop;
    exception
    when no_data_found then
    NULL;
    end;
    end;
    end;

  • Encrypt/Decrypt a file

    I would like to encrypt/decrypt a binary file (not text based) in FLEX 3.4 (AIR). I went through the forum, but I did not found any samples on how to do this. Any idea or help is appreciated.
    Thanks in advanced.

    Take a look at Crypto or ASCrypt3
    http://code.google.com/p/as3crypto/
    http://ascrypt3.riaforge.org/index.cfm

  • TRIPLEDES Encrypt/Decrypt in Oracle

    We are having issues in oracle encryption/decryption.
    In our web application,We receive a number as input from the user which is encrypted & encoded using DES3 in .NET.
    This encrypted value is stored in the oracle database. We need to decrypt it in oracle8.1.7 to get
    the original number entered by the user.
    We are using the following code and facing issues.
    declare
    decrypted_string VARCHAR2(2048);
    input_string VARCHAR2(2048);
    begin
    DBMS_OBFUSCATION_TOOLKIT.DES3Decrypt (input_string=> hextoraw('a403de8264ec0b60a09c6d115768aff0'),
    key_string=>hextoraw('6d6f68616d6d6164616c6c616d6261647368616831323334'),
    Decrypted_string=>decrypted_string);
    dbms_output.PUT_LINE('vr_decrypted is:' || decrypted_string);
    end;
    We have taken the string 'hello ho'.
    This text is encrypted and encode ni .NET in DES3 which is the input string 'a403de8264ec0b60a09c6d115768aff0'.
    and the key is the encoded format of the key used to encrypt the input string.
    we are not getting the decrypted value as expected. thats 'hello ho'

    If I understand what you are trying to accomplish correctly, a better approach might be to protect your data by encrypting the network traffic between the middle tier and the db.  This would ensure the entire sqlnet exchange has been protected and not just any one piece of data.  Once the data has been safely moved to the db tier, you can then use the DB Crypto package to encrypt any individual data you want stored in tables protected.  Doing it this way will prevent you from having extra Forms application code and prevent you from writing your own risky security routine in Java.
    Refer to the Oracle Net Services documentation for information on how to encrypt the net traffic between client and db. Remember that the "client" in this case is the middle tier Forms environment and not the end-user.  Here are some helpful references:
    http://docs.oracle.com/cd/B28359_01/network.111/b28530/toc.htm
    http://docs.oracle.com/cd/B28359_01/network.111/b28316/toc.htm

  • Encrypt-Decrypt in XI

    Hi ,
       Can any one explain me how do u perform encryption decryption in XI
       with an example.
       I Just knw that it is possible through Java  mapping.
      but i dont knw how to do it. can any one send a sample code on
      [email protected]
       Is it possible through ABAP mapping ?
    Regards

    Hi
    Go through this
    http://help.sap.com/saphelp_nw04s/helpdata/en/4f/65c3b32107964996a56e4165077e24/frameset.htm
    http://help.sap.com/saphelp_nw04s/helpdata/en/a4/d0201854fb6a4cb9545892b49d4851/frameset.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/55ba9790-0201-0010-aa98-ce8f51ea93cd
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/b2e7020d-0d01-0010-269c-a98d3fb5d16c
    http://help.sap.com/saphelp_nw04s/helpdata/en/a8/882a40ce93185de10000000a1550b0/content.htm
    /people/sap.user72/blog/2005/06/16/using-digital-signatures-in-xi
    How to achieve encryption in XI
    Encryption in XI
    XI Encryption
    Thanks

  • Regarding encryption/decryption in sender HTTP Adapter...

    Hi experts,
              I have  a doubt that ... is there any possible ways to encrypt/decrypt the username, password  using sender side Plain HTTP adapter.
    Regards,
    Sasitharan

    hi
    You can use those adapters to define transport level security(HTTPS/FTPS) and message level security (encryption).
    hi check this thread for refernce:
    How to use the Private/Public Keys from the Key Store
    Also check this document on encryption in adpaters:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/482aae19-0301-0010-3485-8efd618818d0
    Check security settings section of this page:
    http://help.sap.com/saphelp_nw04/helpdata/en/da/7a2f41b239a831e10000000a1550b0/content.htm
    Check thiss blog as well:
    /people/varadharajan.krishnasamy/blog/2007/05/11/how-to-use-digital-certificates-for-signing-encrypting-messages-in-xi
    regards
    chandrakanth

Maybe you are looking for

  • 500 Internal Server error for a single report in a dashboard

    Hi All, I had an issue with a report in a dashboard i.e.., In a dashboard a report is prepared by using the opaque view. When I ran the report in a dashboard it ran for about 15 to 20 mins and the report is excuted with the data. Now I tried to downl

  • Macbook display darken on startup?

    Hi Guys, Quick question about my macbook. For quite a while now, on startup, the display brightness is darker than what it previously was. I will go into sydtem preferences, brighten the screen, hen often when re-starting or waken the computer from s

  • Engineer to Relational does nothing DM3 Production

    Hi, Has anyone had this experience where you click on the >> button to engineer to a relational model and nothing happens? no error, no warning and no dialog box. The model I am working with was created in EA3 and I simply opened it in Production to

  • Chromebook power adaptor

    I'm one of the lucky early adopters who got a suspect power adaptor with an HP11 Ch romebook.  I've been asked to return it, and onscreen the instructions ask me to choose which type it is.  Unfortunately not only is the text on the picture of the po

  • Files not showing

    I Have InDesign CS3, and i tried to load some portfolio work that i had done last year in InDesign. The files opened the programand the toolbars are all there, but no no work is being shown. I went into the View tab and the Print Overview option that