Patricia Andersen

Ranch Hand
+ Follow
since Jul 17, 2013
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Patricia Andersen

Richard Tookey wrote:It is not obvious from your code what you are trying to do except that it must be an assignment since in general one needs two programs; one to encrypt the cleartext to create the ciphertext and the other to decrypt the ciphertext to recover the cleartext. As an exercise one can just use one program but use two sections; one to encrypt and one to decrypt.

Preliminary -

Create the RSA public and private keys. The public key will be used in the encryption section and the private key used in the decryption.

Encryption section -

1) Create a random AES key.
2) Encrypt this AES key with the RSA public key. Write the encrypted key it to the output.
3) Create a random IV for use with AES encryption.
4) Write it to the output.
5) Encrypt your cleartext with AES using the random AES key and random IV. Write the result to the output.

Decryption section -

1) Read the encrypted AES key from the input.
2) Decrypt the encrypted AES key using the RSA private key.
3) Read the IV from the input.
4) Using the exracted AES key and extracted IV decrypt the rest of the input. This is the recovered cleartext.

Note 1 - DataOutputStream and DataInputStream are very useful in reading and writing since they allow you to write a set of bytes as a length followed by the bytes.
Note 2 - Since this is an exercise you can chain the DataOutputStream to a ByteArrayOutptuStream if you don't actually want to save the output to a file. You can then use the content of the ByteArrayInput to a ByteArrayInputStream chained to a DataInputStream for use in decryption.
Note 3 - You can get away with using ECB mode in the AES cipher as long as you use a random AES key. You would then ignore the IV requirement.





Yes thank you. Its an assignment but we were supposed to create two programmes but it was ok dto do just one if we managed to solve it that way but come to think of it i think its better to do two. Thank you for your help. Ive been thinking about outputstream encrypting a file and send it that way but didnt thinnk it was necessary in just one programme but maybe its better. Thanks for your advice and help.
6 years ago

Richard Tookey wrote:

Stephan van Hulst wrote:Keep in mind that both AES and RSA may use block ciphers that use an initialization vector, so when you initialize a cipher for decryption, you may need to pass it the IV used by the encrypting cipher.



If RSA is being used to encrypt the AES key then it should use something like PKCS1 padding since that padding introduces a random element. AES used with ECB padding is susceptible to ciphertext forgery and in order to avoid this AES should always be used with one of the feedback modes such as CBC and use a random IV. The random IV does not need to be kept secret and can be passed in the clear along with the AES ciphertext. One approach is to pre-pend the IV to the AES ciphertext. Using this approach one would ship the RSA encrypted AES key followed by the IV followed by the AES cyphertext.




Thanks for advice you guys... my issue is atm that i do not know where in my code to re-use the encrypted data in order to decrypt it. I just feel lost and confused. I have used the PKCS1 padding thanks to your advice and im not getting that kind of error any longer. I thought padding error had to do with the fact that i was trying to convert byte to string but maybe thats not correct? In any case right now im trying to figure out how to re-use my encrypted string "InputText1". Im starting to think that maybe it is complicated to decrypt a string that is not a pre-defined specific word or sentence like lets say "Hello world", or does it matter? It worked to encrypt so should work to decrypt as well. Sorry ive been working with this for a while and i just feel dizzy lately :P
6 years ago

Stephan van Hulst wrote:You're encrypting your message using a symmetric key, and then you're never using that encrypted data again. You're only decrypting your symmetric key. You still need to decrypt your message using your decrypted key.



so im only decrypting the AES key not the message and RSA key itself? thanks, need to take a look at it.
6 years ago

Campbell Ritchie wrote:Too difficult for this forum: moving.
Also breaking up the excessively long line).



Sorry, didnt know
6 years ago

fred rosenberger wrote:How do you know it doesn't work? What I mean is, do you get a compiler error? a run time error? Does it throw an exception? Does it run to completion, but the data it decrypted doesn't match what was encrypted?

Help us help you and TellTheDetails.



No errors, beautifully smoothly compiling just not decrypting it at all and it has to be decrypted with the RSA private key so im very stuck on what im doing wrong :/
6 years ago

fred rosenberger wrote:How do you know it doesn't work? What I mean is, do you get a compiler error? a run time error? Does it throw an exception? Does it run to completion, but the data it decrypted doesn't match what was encrypted?

Help us help you and TellTheDetails.




Oh im sorry, i wasnt clear. Well i get the pop up asi want from JOptionPane message dialog the message encrypted but not decrypted. So what i see is a message saying :: text encrpyted : fuhgudhgug and text decrypted : fhdhgidg

(as an example) . So it doesnt decrypt it with the private key i suspect.
6 years ago
I am about to break down and cry and therefor after almost weeks of trying to understand and solve this i now need a little push into the right direction.

So to explain what i need to do in this programme, is to create an AES key and a private and public key using RSA algorithm. I then wanna encrypt a msg with the AES key and then encrypt that AES key with the RSA public key. And in the end decrypt the message with the RSA private key.


I have only managed to encrypt the message with AES , i have also encrypted the AES key with RSA public key but i cant seem to get the decrytion to work, in other words to decrypt that message with the private key. Im not sure how to move forward, im totally stuck.


Any advice? here is the code. Im very new to cryptography

6 years ago
Hi guys!

I have a small issue with my code where im encrypting and decrypting messages. My import org.apache.commons.codec.binary.Base64;. does not work. It says binary does not exist_ Any idea why this happens?. Ive downloaded the codec but im starting to wonder if it has to do with where the codec folder is located, but i may be wrong. Any ideas?



thanks in advance
6 years ago
Too bad no one could help
Im still trying to understand this as hard as i can. Id really appriciate any sort of help
6 years ago
Hi guys,

Im not sure if I am allowed to ask this question here but its related to Java so i hope so. I am going to write an encryption code with java but what i have to do first is an encryption and decryption "test" with RSA using p = 7, q = 11, e = 17 and ”plaintext” M = 8. ( i know that M is the secret message we wanna encrypt here)

I have understood so far that pq = n which is 77
n is one of the public keys
and getting the φ(n) totient i use Eulers function and get the answer 60

so i have n = 77, φ= 60 and e = 17 and M = 8


My ISSUE however is finding d!! In other words the private key. I know im supposed to use Euclids algorithm but i just dont get it. Ive read and tried like a million times, since yesterday and i cannot get it in to my head. I need easy instructions as it seems im a total brain dead person when it comes to maths
I need to use this type of calculation later on in a java code so I really need to understand how i encrypt.

IF anyone is used to this and willing to help id love if you could. A classmate said that the answer to d will be 53.
I just dont get how he got that number thouht....since i dont get euclids algorithm.

THanks in advance

6 years ago

Stefan Evans wrote:Ok, so to insert a value into the kontoagare table, you need an entry in the konto table first.
That is not there, and thus explains the error message you posted.

Why is that value not there?
Presumably trying to insert the record into the konto gives you a similar message, complaining about the ktrn column?

so taking a further step back, are there any records in the kontotyp table?
If not, what happens when you execute just THAT insert statement?

My suggestion:
Execute those statements you have listed one by one. The first time you get an error message, stop and fix that one, because none of the others after it will work.



Hi Stefan,

Im sorry i didnt reply, i had some issues yesterday with my network. SO anyway i managed to solve it, and to be honest i dont understand how it got solved since i just deleted everything and started from the beginning and suddenly it worked. I was thinking oracle had some problem or maybe i did everything in a different order (but i dont think so)
Anyway thanks a million for your efforts to help me.

Stefan Evans wrote:From your error message, the constraint that is failing is: V07PATTR.KONTOÄGARE_KNR_FK
That points to being the Table: Kontoagare, knr column which references konto.knr

I presume this error comes when running an insert into kontoagare?


thanks for replying. Yes it is

Looking at your insert statements, you do appear to have created parent records appropriately.
For instance the knr value of 123 in the above statement was inserted:


Is it actually there?
If you select * from konto where knr=123, do you get that record back?

No its not..thats the problem. Nothing gets inserted and i just get that error message which i find very odd

The other foreign key reference is the pnr field which references the Bankkund table.
You haven't shown any statements to populate the Bankkund table. Does the value '540126-1111' appear in that table?
there are no values added in the table whatsoever..thats why i am sooo confused. No values and primary key error.... ive been googling for days and went through my tables at least 50 times... cannot figure out the problem

Hi guys,

Im stuck working with my tables trying to add some values to three of the tables but im getting this error:

SQL Error: ORA-02291: "integrity constraint (%s.%s) violated - parent key not found" (V07PATTR.KONTOÄGARE_KNR_FK)
*Cause: A foreign key value has no matching primary key value.
*Action: Delete the foreign key or add a matching primary key.
commited.

I understand what this error means so that is not the problem, i just cannot find anything wrong within my tables, everything seems to be in order . So these are the tables i first created

CREATE TABLE BANKKUND
(
PNR VARCHAR2(11) not null,
FNAMN VARCHAR2(25) not null,
ENAMN VARCHAR2(25) not null,
PASSWD VARCHAR2(6) not null,
constraint BANKKUND_pnr_pk primary key(PNR));

CREATE TABLE KONTOTYP
(
KTNR NUMBER(6) not null,
KTNAMN VARCHAR2(20) not null,
RÄNTA NUMBER(5,2) not null,
constraint KONTOTYP_ktnr_pk primary key(KTNR));

CREATE TABLE KONTO(
KNR NUMBER(8) not null,
KTNR NUMBER(6) not null,
REGDATUM DATE not null,
SALDO NUMBER(10,2),
constraint KONTO_knr_pk primary key(KNR),
constraint KONTO_ktnr_fk foreign key(KTNR) references KONTOTYP(KTNR));

CREATE TABLE KONTOÄGARE(
RADNR NUMBER(9) not null,
PNR VARCHAR2(11) not null,
KNR NUMBER(8) not null,
constraint KONTOÄGARE_radnr_pk primary key(RADNR),
constraint KONTOÄGARE_pnr_fk foreign key(PNR) references BANKKUND(PNR),
constraint KONTOÄGARE_knr_fk foreign key(KNR) references KONTO(KNR));

CREATE TABLE UTTAG(
RADNR NUMBER(9) not null,
PNR VARCHAR2(11) not null,
KNR NUMBER(8) not null,
BELOPP NUMBER(10,2),
DATUM DATE not null,
constraint UTTAG_radnr_pk primary key(RADNR),
constraint UTTAG_knr_fk foreign key(KNR) references KONTO(KNR));

CREATE TABLE INSÄTTNING(
RADNR NUMBER(9) not null,
PNR VARCHAR2(11) not null,
KNR NUMBER(8) not null,
BELOPP NUMBER(10,2),
DATUM DATE not null,
constraint INSÄTTNING_radnr_pk primary key(RADNR),
constraint INSÄTTNING_knr_fk foreign key(KNR) references KONTO(KNR));

CREATE TABLE ÖVERFÖRING(
RADNR NUMBER(9) not null,
PNR VARCHAR2(11) not null,
FRÅN_KNR NUMBER(8) not null,
TILL_KNR NUMBER(8) not null,
BELOPP NUMBER(10,2),
DATUM DATE not null,
constraint ÖVERFÖRING_radnr_pk primary key(RADNR),
constraint ÖVERFÖRING_FRÅN_fk foreign key(FRÅN_KNR) references KONTO(KNR),
constraint ÖVERFÖRING_till_fk foreign key(TILL_KNR) references KONTO(KNR))


and these are the values im trying to add to my tables kontotyp, konto and kontoägare'

Create sequence radnr_seq
Start with 1
Increment by 1;

INSERT INTO kontotyp(ktnr,ktnamn,ränta)
VALUES(1,'bondkonto',3,4);
INSERT INTO kontotyp(ktnr,ktnamn,ränta)
VALUES(2,'potatiskonto',4,4);
INSERT INTO kontotyp(ktnr,ktnamn,ränta)
VALUES(3,'griskonto',2,4);
COMMIT;
INSERT INTO konto(knr,ktnr,regdatum,saldo)
VALUES(123,1,SYSDATE - 321,0);
INSERT INTO konto(knr,ktnr,regdatum,saldo)
VALUES(5899,2,SYSDATE - 2546,0);
INSERT INTO konto(knr,ktnr,regdatum,saldo)
VALUES(5587,3,SYSDATE - 10,0);
INSERT INTO konto(knr,ktnr,regdatum,saldo)
VALUES(8896,1,SYSDATE - 45,0);
COMMIT;
INSERT INTO kontoägare(radnr,pnr,knr)
VALUES(radnr_seq.NEXTVAL,'540126-1111',123);
INSERT INTO kontoägare(radnr,pnr,knr)
VALUES(radnr_seq.NEXTVAL,'691124-4478',123);
INSERT INTO kontoägare(radnr,pnr,knr)
VALUES(radnr_seq.NEXTVAL,'540126-1111',5899);
INSERT INTO kontoägare(radnr,pnr,knr)
VALUES(radnr_seq.NEXTVAL,'691124-4478',8896);
COMMIT;

Im sorry if i made a mistake with the code, i usually post in this forum questions connected to java but never asked for SQL so i have no idea how to present the code in here. Anyhow i hope that someone can see my mistake because ive tried for 3 days now and i just cannot understand what is wrong.

Thanks in advance
]Hi all,

Im doing an excersize in java since i have a big exam in like 3 weeks and I´ve googled for like 5 days now tried different things without result but now I have like 3 hairs left on my head so I need to ask because I have issues i cannot solve no matter what i do.

I have to read this CSV file into an arraylist. Arraylist i call weight. The data in the csv file has 200 double values which is the weight of all the 200 bananas. Since the csv file is a string i guess I cannot create an double arraylist from scratch, but i have to parse the csv file afterwards, right? Well this does not work and ill show you the code in a bit, just need to state all my issues.

My second issue is how to be able to print out the the weight items (in this case bananas) next to the weight of the bananas taken from the array?
This has to be done by the help of a constructor i assume? I just dont know how constructors work with arraylists.

Id like it to look something like this in the output window.

Banana 34,55
Banana 43,55
Banana 23,74

and so on (200 times)

so these are my issues, how to parse and how to print the arraylist weights and the item banana in the output window with the help of a constructor. Here is the code.








Thanks in advance
6 years ago

Winston Gutkowski wrote:

Patricia Andersen wrote:All i asked for is if there is a need for a 3rd loop. And i am trying to break the problem down into small chunks which is why i wonder if there is a need for a 3rd loop.


But:
  • You still have only one method, and it's static.
  • You're thinking about things like loops, which is the how, when what you should be concentrating on is understanding what needs to be done.

  • If you just want answers, you're probably better off with a site like Stackoverflow. Here, we try to help you.

    Winston



    Ok you are right..but still even if i try to break it down into small pieces i still need to know the syntax and what should be used. Anyhow, i appriciate your help
    7 years ago