Decrypt a JWE using list of keys that are stored in DB using JAVA 8 Lambda The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceConverting array to list in Javalist comprehension vs. lambda + filterRetrieving a List from a java.util.stream.Stream in Java 8Java 8 Lambda function that throws exception?Ways to iterate over a list in JavaJava 8 List<V> into Map<K, V>Find first element by predicateJava Lambda Stream Distinct() on arbitrary key?Java 8 lambdas using if else on list streamHow to use a Java 8 Lambda expression to convert a List of one type to a List of its subtype

The following signatures were invalid: EXPKEYSIG 1397BC53640DB551

Do working physicists consider Newtonian mechanics to be "falsified"?

Why did all the guest students take carriages to the Yule Ball?

Can undead you have reanimated wait inside a portable hole?

How to test the equality of two Pearson correlation coefficients computed from the same sample?

Derivation tree not rendering

RT6224D-based step down circuit yields 0V - why?

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

How can I protect witches in combat who wear limited clothing?

Difference between "generating set" and free product?

How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?

First use of “packing” as in carrying a gun

Button changing its text & action. Good or terrible?

Is there a writing software that you can sort scenes like slides in PowerPoint?

Why is superheterodyning better than direct conversion?

The variadic template constructor of my class cannot modify my class members, why is that so?

How is simplicity better than precision and clarity in prose?

What do you call a plan that's an alternative plan in case your initial plan fails?

Relations between two reciprocal partial derivatives?

Keeping a retro style to sci-fi spaceships?

Create an outline of font

What was the last x86 CPU that did not have the x87 floating-point unit built in?

Single author papers against my advisor's will?

He got a vote 80% that of Emmanuel Macron’s



Decrypt a JWE using list of keys that are stored in DB using JAVA 8 Lambda



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceConverting array to list in Javalist comprehension vs. lambda + filterRetrieving a List from a java.util.stream.Stream in Java 8Java 8 Lambda function that throws exception?Ways to iterate over a list in JavaJava 8 List<V> into Map<K, V>Find first element by predicateJava Lambda Stream Distinct() on arbitrary key?Java 8 lambdas using if else on list streamHow to use a Java 8 Lambda expression to convert a List of one type to a List of its subtype



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I Have a JWE which is to be decrypted using list of keys stored in DB. I have to try each key until I find the one that actually decrypts.



I am trying to do it in JAVA 8 way, writing Lambdas But I am unable to understand how to do it.



I have written following code



List<String> listKeys = myMapper.getDistinctEncKeyIds().stream() .map(MyMapper::encrypTionIdsfromDbData).collect(Collectors.toList());


This gives me list of keys and I am writing normal java code



for(int i=0; i<listKeys.size();i++) 
try
decryptedToken= decrypt(token,listKeys.get(i));
catch(Exception e)
log.info("key not found: %s", e);




I want to convert it into JAVA 8 lambda code because that takes less no of lines and is easier to use something like this



myMapper.getDistinctEncKeyIds().stream()
.map(myMapper::encrypTionIdsfromDbData)
.filter(key-> decrypt(token,key))
.findFirst();


But I have two issues here



  1. Decrypt Method actually returns a key and filter takes a method which returns a boolean

  2. Decrypt method throws JOSEException, again I get an error in filter and I have to write try/catch block in the lambda

My Aim is to find the key that actually decrypts this token and return that key. I am not getting how to write it in java 8. Thanks in advance.










share|improve this question






















  • What does decrypt return when it cannot decrypt a key?

    – Amardeep Bhowmick
    Mar 22 at 6:21











  • I run decrypt(token,key) in a loop passing each key and it returns the key which decrypts. This logic works fine. My question is hot to call decrypt after getting the keys in this lambda and return the key which has decrypted it. "myMapper.getDistinctEncKeyIds().stream() .map(myMapper::encrypTionIdsfromDbData) "

    – ankita m
    Mar 22 at 6:45












  • Your imperative style of writing the code is also incomplete in terms of the final operation and initial assignments if there are any. Due to which the question is quite unclear imho.

    – Naman
    Mar 22 at 7:13

















0















I Have a JWE which is to be decrypted using list of keys stored in DB. I have to try each key until I find the one that actually decrypts.



I am trying to do it in JAVA 8 way, writing Lambdas But I am unable to understand how to do it.



I have written following code



List<String> listKeys = myMapper.getDistinctEncKeyIds().stream() .map(MyMapper::encrypTionIdsfromDbData).collect(Collectors.toList());


This gives me list of keys and I am writing normal java code



for(int i=0; i<listKeys.size();i++) 
try
decryptedToken= decrypt(token,listKeys.get(i));
catch(Exception e)
log.info("key not found: %s", e);




I want to convert it into JAVA 8 lambda code because that takes less no of lines and is easier to use something like this



myMapper.getDistinctEncKeyIds().stream()
.map(myMapper::encrypTionIdsfromDbData)
.filter(key-> decrypt(token,key))
.findFirst();


But I have two issues here



  1. Decrypt Method actually returns a key and filter takes a method which returns a boolean

  2. Decrypt method throws JOSEException, again I get an error in filter and I have to write try/catch block in the lambda

My Aim is to find the key that actually decrypts this token and return that key. I am not getting how to write it in java 8. Thanks in advance.










share|improve this question






















  • What does decrypt return when it cannot decrypt a key?

    – Amardeep Bhowmick
    Mar 22 at 6:21











  • I run decrypt(token,key) in a loop passing each key and it returns the key which decrypts. This logic works fine. My question is hot to call decrypt after getting the keys in this lambda and return the key which has decrypted it. "myMapper.getDistinctEncKeyIds().stream() .map(myMapper::encrypTionIdsfromDbData) "

    – ankita m
    Mar 22 at 6:45












  • Your imperative style of writing the code is also incomplete in terms of the final operation and initial assignments if there are any. Due to which the question is quite unclear imho.

    – Naman
    Mar 22 at 7:13













0












0








0








I Have a JWE which is to be decrypted using list of keys stored in DB. I have to try each key until I find the one that actually decrypts.



I am trying to do it in JAVA 8 way, writing Lambdas But I am unable to understand how to do it.



I have written following code



List<String> listKeys = myMapper.getDistinctEncKeyIds().stream() .map(MyMapper::encrypTionIdsfromDbData).collect(Collectors.toList());


This gives me list of keys and I am writing normal java code



for(int i=0; i<listKeys.size();i++) 
try
decryptedToken= decrypt(token,listKeys.get(i));
catch(Exception e)
log.info("key not found: %s", e);




I want to convert it into JAVA 8 lambda code because that takes less no of lines and is easier to use something like this



myMapper.getDistinctEncKeyIds().stream()
.map(myMapper::encrypTionIdsfromDbData)
.filter(key-> decrypt(token,key))
.findFirst();


But I have two issues here



  1. Decrypt Method actually returns a key and filter takes a method which returns a boolean

  2. Decrypt method throws JOSEException, again I get an error in filter and I have to write try/catch block in the lambda

My Aim is to find the key that actually decrypts this token and return that key. I am not getting how to write it in java 8. Thanks in advance.










share|improve this question














I Have a JWE which is to be decrypted using list of keys stored in DB. I have to try each key until I find the one that actually decrypts.



I am trying to do it in JAVA 8 way, writing Lambdas But I am unable to understand how to do it.



I have written following code



List<String> listKeys = myMapper.getDistinctEncKeyIds().stream() .map(MyMapper::encrypTionIdsfromDbData).collect(Collectors.toList());


This gives me list of keys and I am writing normal java code



for(int i=0; i<listKeys.size();i++) 
try
decryptedToken= decrypt(token,listKeys.get(i));
catch(Exception e)
log.info("key not found: %s", e);




I want to convert it into JAVA 8 lambda code because that takes less no of lines and is easier to use something like this



myMapper.getDistinctEncKeyIds().stream()
.map(myMapper::encrypTionIdsfromDbData)
.filter(key-> decrypt(token,key))
.findFirst();


But I have two issues here



  1. Decrypt Method actually returns a key and filter takes a method which returns a boolean

  2. Decrypt method throws JOSEException, again I get an error in filter and I have to write try/catch block in the lambda

My Aim is to find the key that actually decrypts this token and return that key. I am not getting how to write it in java 8. Thanks in advance.







java lambda






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 6:16









ankita mankita m

83




83












  • What does decrypt return when it cannot decrypt a key?

    – Amardeep Bhowmick
    Mar 22 at 6:21











  • I run decrypt(token,key) in a loop passing each key and it returns the key which decrypts. This logic works fine. My question is hot to call decrypt after getting the keys in this lambda and return the key which has decrypted it. "myMapper.getDistinctEncKeyIds().stream() .map(myMapper::encrypTionIdsfromDbData) "

    – ankita m
    Mar 22 at 6:45












  • Your imperative style of writing the code is also incomplete in terms of the final operation and initial assignments if there are any. Due to which the question is quite unclear imho.

    – Naman
    Mar 22 at 7:13

















  • What does decrypt return when it cannot decrypt a key?

    – Amardeep Bhowmick
    Mar 22 at 6:21











  • I run decrypt(token,key) in a loop passing each key and it returns the key which decrypts. This logic works fine. My question is hot to call decrypt after getting the keys in this lambda and return the key which has decrypted it. "myMapper.getDistinctEncKeyIds().stream() .map(myMapper::encrypTionIdsfromDbData) "

    – ankita m
    Mar 22 at 6:45












  • Your imperative style of writing the code is also incomplete in terms of the final operation and initial assignments if there are any. Due to which the question is quite unclear imho.

    – Naman
    Mar 22 at 7:13
















What does decrypt return when it cannot decrypt a key?

– Amardeep Bhowmick
Mar 22 at 6:21





What does decrypt return when it cannot decrypt a key?

– Amardeep Bhowmick
Mar 22 at 6:21













I run decrypt(token,key) in a loop passing each key and it returns the key which decrypts. This logic works fine. My question is hot to call decrypt after getting the keys in this lambda and return the key which has decrypted it. "myMapper.getDistinctEncKeyIds().stream() .map(myMapper::encrypTionIdsfromDbData) "

– ankita m
Mar 22 at 6:45






I run decrypt(token,key) in a loop passing each key and it returns the key which decrypts. This logic works fine. My question is hot to call decrypt after getting the keys in this lambda and return the key which has decrypted it. "myMapper.getDistinctEncKeyIds().stream() .map(myMapper::encrypTionIdsfromDbData) "

– ankita m
Mar 22 at 6:45














Your imperative style of writing the code is also incomplete in terms of the final operation and initial assignments if there are any. Due to which the question is quite unclear imho.

– Naman
Mar 22 at 7:13





Your imperative style of writing the code is also incomplete in terms of the final operation and initial assignments if there are any. Due to which the question is quite unclear imho.

– Naman
Mar 22 at 7:13












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293906%2fdecrypt-a-jwe-using-list-of-keys-that-are-stored-in-db-using-java-8-lambda%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293906%2fdecrypt-a-jwe-using-list-of-keys-that-are-stored-in-db-using-java-8-lambda%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해