This forum is currently locked. You can't register or post questions at this time. (read more)

Public and Private Key Concept - Oracle PL/SQL

All posts relating to Oracle PL/SQL development.

Moderator: Tim...

venkat
Member
Posts: 30
Joined: Sat Jan 05, 2013 5:13 am

Public and Private Key Concept - Oracle PL/SQL

Postby venkat » Mon Aug 25, 2014 7:28 am

Hi Tim,

Any standard API's are available to generate the Public key and private key
I need to decrypt using my private key and sender can send encrypt the message using Public key

Thanks & Regards
Venkat

Tim...
Site Admin
Posts: 18437
Joined: Mon Nov 01, 2004 5:56 pm
Location: England, UK
Contact:

Re: Public and Private Key Concept - Oracle PL/SQL

Postby Tim... » Mon Aug 25, 2014 9:20 am

Hi.

Depends what you mean...

You can just use SSL in the normal way over HTTPS. That is doing exactly that. :)

Cheers

Tim...
Tim...
Oracle ACE Director
Oracle ACE of the Year 2006 - Oracle Magazine Editors Choice Awards
OakTable Member
OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
OCP Advanced PL/SQL Developer
Oracle Database: SQL Certified Expert
My website: http://www.oracle-base.com
My blog: http://www.oracle-base.com/blog

venkat
Member
Posts: 30
Joined: Sat Jan 05, 2013 5:13 am

Re: Public and Private Key Concept - Oracle PL/SQL

Postby venkat » Tue Aug 26, 2014 3:52 am

Hi tim,

Thanks For Your Response

For Example i am using - DBMS_Crypto to decrypt the encrypted plain text using the key which was send by the sender
where the secret key is hardcoded
I want to generate a public key to sender and want to decrypt the encoded text using the private Key

can you please suggest me

Thanks & Regards
Venkat

Tim...
Site Admin
Posts: 18437
Joined: Mon Nov 01, 2004 5:56 pm
Location: England, UK
Contact:

Re: Public and Private Key Concept - Oracle PL/SQL

Postby Tim... » Tue Aug 26, 2014 6:46 am

Hi.

Sorry. I don't really know what to suggest!

Personally, I would set up the data transfer that uses a web service over SSL, that way all the encryption/decryption is done for you by the protocol.

Cheers

Tim...
Tim...
Oracle ACE Director
Oracle ACE of the Year 2006 - Oracle Magazine Editors Choice Awards
OakTable Member
OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
OCP Advanced PL/SQL Developer
Oracle Database: SQL Certified Expert
My website: http://www.oracle-base.com
My blog: http://www.oracle-base.com/blog

venkat
Member
Posts: 30
Joined: Sat Jan 05, 2013 5:13 am

Re: Public and Private Key Concept - Oracle PL/SQL

Postby venkat » Thu Aug 28, 2014 5:55 am

Hi Tim,

Got the Solution By Using Java API here is the sample Code ( :) Copy Paste Program Only)

Code: Select all

create or replace type widgets_t is table of varchar2(32767);

create or replace and compile java source named "so19ja" as
import java.lang.*;
import java.security.KeyPairGenerator;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.KeyFactory;
import java.security.spec.EncodedKeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.RSAPrivateKeySpec; 
import java.security.spec.RSAPublicKeySpec; 
public class so19ja {
    public static String[] get_widgets_as_array() {
      String Private_Key ;
      String Public_Key  ;
      try {
     
                KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
                keyGen.initialize(1024);
                KeyPair keyPair = keyGen.genKeyPair();
                PrivateKey privateKey = keyPair.getPrivate();
                PublicKey  publicKey  = keyPair.getPublic();
                KeyFactory keyFactory = KeyFactory.getInstance("RSA");
                System.out.println("\n------- PULLING OUT PARAMETERS WHICH MAKES KEYPAIR----------\n");   
                RSAPrivateKeySpec rsaPrivKeySpec = keyFactory.getKeySpec(privateKey, RSAPrivateKeySpec.class); 
                RSAPublicKeySpec rsaPubKeySpec   = keyFactory.getKeySpec(publicKey, RSAPublicKeySpec.class);
                Private_Key = rsaPrivKeySpec.getModulus().toString().concat(rsaPrivKeySpec.getPrivateExponent().toString());
                Public_Key  = rsaPubKeySpec.getModulus().toString().concat(rsaPubKeySpec.getPublicExponent().toString());
                String[] widgets = new String[]{Private_Key,Public_Key};
                return widgets;
     
      }
     
       catch (InvalidKeySpecException specException) {

                System.out.println("Exception");
                System.out.println("Invalid Key Spec Exception");
                 //String[] widgets = new String[]{"foo", "bar", "zoo"};
               
            }
           
     catch (NoSuchAlgorithmException e) {

                System.out.println("Exception");
                System.out.println("No such algorithm: " + "RSA");
              // String[] widgets = new String[]{"foo", "bar", "zoo"};
            }       
           
        String[] widgets = new String[]{"foo", "bar", "zoo"};
        return widgets;
    }

    public static java.sql.Array array_wrapper(
        String typeName,
        Object elements
    ) throws java.sql.SQLException {
        oracle.jdbc.OracleDriver ora = new oracle.jdbc.OracleDriver();
        java.sql.Connection conn = ora.defaultConnection();
        oracle.jdbc.OracleConnection oraConn =
            (oracle.jdbc.OracleConnection)conn;
        /* Yeah - typeName have to be UPPERCASE, really. */
        java.sql.Array arr =
            oraConn.createARRAY(typeName.toUpperCase(), elements);
        return arr;
    }

    public static java.sql.Array get_widgets_as_array_wrapped()
    throws java.sql.SQLException {
        return array_wrapper("widgets_t", get_widgets_as_array());
    }
};
/
show errors java source "so19ja"


declare
  widgets constant widgets_t := get_widgets_as_array;
  Private_key    raw(1000);
  Public_Key     raw(1000);
begin
  for i in widgets.first .. widgets.last loop
 
     Private_key := Case When i = 1 then widgets(i) end;
     Public_Key  := Case When i = 2 then widgets(i) end;
     
    dbms_output.put_line( Case When i = 1 then 'Private Key '
                                  When i = 2 Then 'Public Key ' end ||'  = ' || widgets(i));
   
     
   
  end loop;
 
 

   
end;



Thanks & Regards
Venkat

Tim...
Site Admin
Posts: 18437
Joined: Mon Nov 01, 2004 5:56 pm
Location: England, UK
Contact:

Re: Public and Private Key Concept - Oracle PL/SQL

Postby Tim... » Thu Aug 28, 2014 9:31 am

OK. :)
Tim...
Oracle ACE Director
Oracle ACE of the Year 2006 - Oracle Magazine Editors Choice Awards
OakTable Member
OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
OCP Advanced PL/SQL Developer
Oracle Database: SQL Certified Expert
My website: http://www.oracle-base.com
My blog: http://www.oracle-base.com/blog


Return to “Oracle SQL and PL/SQL Development”

Who is online

Users browsing this forum: No registered users and 5 guests

cron