I have an Apex web service that takes a query string. I need to update this class to take an encrypted string, find the appropriate record in Salesforce, and then return an encrypted JSON response. I am struggling with writing the unit test for this. I have read through the Crypto Class documentation and am working on the trailhead but I expect I am missing something here.  In my unit test, I have encrypted the lastName param and added to the request.addParmater by calling String.valueOf of the encrypted Blob value. But when I try to decrypt in my API I get an error of Unrecognized base 64 character. This makes think I am misunderstanding how to pass the data to the web service and was hoping I could ask for some help here.  The error happens when I call the EncodingUtil on the string from the request params.   I apologize if the code is a little awkward, just trying to add the encryption in.   Here is part of the GET endpoint   @HttpGet     global static void getPatient() {         Blob cryptoKey = Blob.valueOf(Label.Okta_User_API_Cypto_Key);         System.debug('crypto key value');          RestResponse response = RestContext.response;         String email = RestContext.request.params.get('email');         String phone = RestContext.request.params.get('primaryPhone');         String lastName = RestContext.request.params.get('lastName');         String productSerNum = RestContext.request.params.get('serialNum');             ////test decrypted code here         String lastNametoDecrypt = lastName;         Blob lastNameData = null;         if(lastNametoDecrypt != null){             /////////Error line number here!!!!             lastNameData = EncodingUtil.base64Decode(lastNametoDecrypt);         }         Blob decryptedLastNameData = Crypto.decryptWithManagedIV('AES256', cryptoKey , lastNameData);         String decryptedLastName = decryptedLastNameData.toString();         System.debug('value of decrypted last name ' + decryptedLastName);          /// End test decrypt code }   Below is the unit test  @IsTest static void getPatient() {         Patient__c testPatient = [SELECT First_Name__c, Last_Name__c, Email__c, Birthdate__c, Home_Phone__c         FROM Patient__c LIMIT 1];         // Set up a test request         RestRequest request = new RestRequest();         RestResponse response = new RestResponse();          Blob cryptoKey = Blob.valueOf(Label.Okta_User_API_Cypto_Key);          Blob lastname = Blob.valueOf('kirk');                Blob encrypted = Crypto.encryptWithManagedIV('AES256', cryptoKey, lastname);          request.addParameter('email', testPatient.Email__c );                request.addParameter('lastName', String.valueOf(encrypted));         request.addParameter('primaryPhone', testPatient.Home_Phone__c);         request.addParameter('dob', '1950-01-01');         request.addParameter('serialNum', '12345-54321');         request.httpMethod = 'GET';         RestContext.request = request;         RestContext.response = response;         Test.startTest();        AccountClaimAPI.getPatient();        Test.stopTest();         System.assertNotEquals(null, response.responseBody);        System.assertEquals(200, response.statusCode);     }
I had given an cipher text (of JSON string), an IV and a key. I tried decrypting using 's method:      decryptWithManagedIV(algorithmName, privateKey, IVAndCipherText)     //Sample code   Blob key = Blob.valueOf(decryptionKey);   Blob encryptedDatafor = EncodingUtil.base64Decode(bodystring);   Blob decryptedData = Crypto.decryptwithManagedIV('AES128', key, encryptedDatafor);    cipher = decryptedData.toString();   System.debug('Encrypted BodyString: ' +cipher);   and I was able to decrypt the cipher successfully. But when I use the provided IV with the following method:      decrypt(algorithmName, privateKey, initializationVector, cipherText)    //Sample code  Blob exampleIV = Blob.valueOf('HSDlUkhrmfEo7SgM'); //provided IV   Blob key = Blob.valueOf(decryptionKey);  Blob encryptedDatafor = EncodingUtil.base64Decode(bodystring);  Blob decryptedDataIV = Crypto.decrypt('AES128', key, exampleIV, encryptedDatafor);   cipher = EncodingUtil.base64Encode(decryptedDataIV );  System.debug('Encrypted BodyString: ' +cipher);   I get some string which looks like, it is still in the encrypted form (different from the encrypted string I have passed).   Update:  I have tried the below code-snippet based on the suggestion from @identigral, but I am still unable to decrypt the cipher using the IV:  Blob exampleIV = Blob.valueOf('HSDlUkhrmfEo7SgM'); //provided IV  Blob key = Blob.valueOf(decryptionKey); Blob encryptedDatafor = EncodingUtil.base64Decode(bodystring);  String encodedCipherTextAndIV = EncodingUtil.convertToHex(encryptedDatafor); String encodedCipherText = encodedCipherTextAndIV.substring(32); String finCipher = encodedCipherText.difference(encodedCipherTextAndIV); Blob ciphertext = EncodingUtil.convertFromHex(finCipher);   Blob decryptedDataIV = Crypto.decrypt('AES128', key, exampleIV, ciphertext);  decryptStg = EncodingUtil.base64Encode(decryptedDataIV ); System.debug('Decrypted BodyString: ' +decryptStg);
Properties possessed by $H , G/H$ but not G i) Does there exist a group $G$ with a normal subgroup $H$ such that $H , G/H$ are abelian but $G$ is not ?   ii) Does there exist a group $G$ with a normal subgroup $H$ such that $H , G/H$ are cyclic but $G$ is not ? "404. That’s an error." when viewing from Google cache My site is getting 404. That’s an error. message when I click on cached from Google search results.  This is the error message from Google:  That’s an error.   The requested URL /search?q=cache:8kxLAgFrhZQJ:www.mysite.com.....&amp;cd=8&amp;hl=en&amp;ct=clnk&amp;gl=uk was not found on this server. That’s all we know.  What I did before I was getting this error is that about 10 days ago, I moved my hosting from Ixwebhosting to Gearhost (cloud based). I also added 301 redirect from non www to www.  I have no idea why I am getting this error. Please advise what might be the reason if there is a solution for it.  All of my pages are indexed by Google though. Why do Ruby setters need "self." qualification within the class? Book wherein humans were most dangerous/aggressive of numerous species I recall there were two warring alien empires, one of which was led by a race that could telepathically inflict pain on others, but when they tried to do it to humans, it would backfire. something about human's animal instincts being much closer to the surface than the other species.  Humans made the most aggressive and dangerous fighters, so both empires tried to reruit humanity, since the other races involved in the war were fairly monolithic and sided all with one empire or the other. Humanity was all splintered though.  The empire led by the telepathic race claimed that everyone in it was equal but in reality the telepathic race was in charge. Book series about time travel from future to distant past, psychic powers? What is likely to happen when you plug two ends of a network cable to a single switch/router? Will this create problems on the network, or just be ignored? Direction of $d\mathbf{l}$ Hash character in LaTeX Possible Duplicate:          How do you write the # character in LaTeX? tikz trees: How to not draw a single edge In a simple battery + resistor circuit, what form of energy is lost from the electrons upon exiting the resistor? I will give this question a little context. Firstly, as I understand it, as soon as I "close the switch" on a circuit, electric current pretty quickly establishes a steady state where, at any given cross section along a wire, the average kinetic energy of that slice is both constant and equal anywhere along the wire. (Please correct me if I am misunderstanding).   If the average kinetic energy is constant anywhere throughout the wire in the circuit (which confuses me, as I would think that the electrons should all accelerate after exiting the resistor since they are no longer being impeded as much), that means that the average velocity is constant. So, in the example of a simple circuit with a battery of v Volts and a resistor of o Ohms, my question is the following:  Because a 'voltage drop' is known to occur across the resistor, what type energy is being "traded" to generate the heat that radiates from the resistor? I would think that the reflexive answer is "electrical energy"...hence the VOLTAGE drop (the sacrificed energy is clearly not kinetic, as the velocity is constant everywhere). However, I find this confusing. Does this mean that if I had a positive test charge, it would be easier for me to bring it to the beginning of the resistor as compared to bringing it to the end of the resister?     Further, if the correct answer IS "electrical energy", why exactly DOES electrical energy get "dissipated" as the electrons pass through the resistor? I always here the comment Oh! It's because all the electrons are running into densely packed crap which impedes their flow but that to me sounds like a reason for their KINETIC energy to be reduced. However, clearly that's not the case. So, ultimately, I guess the real question is:  **What goes on in the resistor that is literally removing electrical energy **. I am sure that this is a quantum mechanics question, but my quantum mechanics knowledge is not terribly strong. If I could get an answer that is devoid of crazy wave function equations, I would greatly appreciate it. Thanks! Sadly, yesterday I've spilled some water on my MacBook Pro (El Capitan). Before you yell at me - it was closed, turned off and it wasn't a lot of water, the laptop was wet only on the top and under - not inside.  Today I've turned him on. At first battery wasn't recharging for some reason, but SMC reset fixed the problem.  At the first booting speaker was like talking to me, hard to explain but it was weird. Also only right speaker was "talking", despite the fact that only left side of the laptop was watered. Then there was no sound at all, not from the speakers, nor from the headphones. Also microphone's not working. USB ports are okay. The water was spilled from the left side of the laptop. I know this is hardware issue, and something's broken, but I want to be 100% sure. No it's not muted. I've also tried NVRAM reset a few times, but it doesn't fix the problem :(  There might be one factor, before spilling, my laptop "died" for the first time (battery energy ran off), but I doubt it's the case. (but hey, every info matters, right?)  It wouldn't be weird for me, if only left speaker wouldn't work, but built-in microphone not working is kinda weird in this case, isn't it?  I just want to ask you guys, what else can I check, before I'll be 100% sure it's dead inside?  I've plugged in external microphone - it's not working too. How do you challenge the closing of one of your questions? Let's say I have two planets that are one hundred thousand lightyears away from each other. I and my immortal friend on the other planet want to communicate, with a strong laser and a tachyon communication device.  I record a message on the tachyon communication device and release the message at exactly the same time as I activate the laser, both of which are directed to the other planet which is one hundred thousand lightyears away. Say it is the year 0 for both of us at the time I did this.  If tachyons existed, then the message would arrive to my friend before the photons in the laser. It would arrive, say, a thousand years earlier. From my vantage point, that message will arrive to her at year 99,999; the same would be true for my friend's vantage point. However, she will only see the laser at year 100,000.  So since she got the message at year 99,999, she immediately sends me a reply back going through the same procedure as I did. She records a message and releases it at the same time as the laser. The tachyons will arrive 1,000 years earlier than the laser, so for me, I will receive the message at year 199,998. I will receive the laser, however, at year 199,999.  It seems to me that communication this way does not violate causality. I will still have received the message after I had sent it.   If tachyons truly violated causality, though, I realize it should arrive at year -1 for her, and so she can reply to me at year -2, which would mess me up by year 0 as I will ask her how she knew I was planning on sending her a message before I sent it. I could send her a different message, which she would end up receiving at year -1, and will end up confusing her as she would have received one message asking her out, and the other asking her how did she know I was asking her out. She then decides I am crazy and sends me a message at year -2 that she does not want to date me, and so she will have both turned me down and entertained me before I have even asked her out.  On the other hand, let's go back to year 0 and add a third device to our list: an Alcubierre drive. After I send out the message and the laser, I get impatient and do not feel like waiting 99,999 years, so I get on my Alcubierre drive spaceship and arrive on her planet at the same year 0. My friend is not in her office, so I leave a note to her also immortal secretary saying I dropped by and that she should expect a message for her in year 99,999.  I then get back on my Alcubierre drive and land back on my planet, still on year 0. Meanwhile, the tachyons and photons I sent out are still racing to arrive to her. By year 99,999, she receives the message just as I Alcubierre drive back to her, and I pick her up for dinner.  But the point of my question is, it seems to me that just going faster than light, if that alone was what you had, would not violate causality. It must be something else. I understand time dilation and that things with mass cannot travel at the speed of light, but using the Alcubierre drive, hypothetically speaking, I was still able to outpace the photons while also having mass. It still did not produce causality problems. Alcubierre drives are also valid solutions to GR.  It seems circular to me to say that what makes traveling faster than light violate causality is because it violates causality (if faster than light communication was divorced from causality problems, then the causality problem would cause itself -- thereby violating causality and, hence, we would scrap it and conclude that there is no causality problem after all).  What is it that I am missing? If someone could help me out, that would be excellent. I've been itching to ask my friend out for a few millenia now. :) Does there exist an $a_0$ such that the sequence $a_{n+1} = 2a_n + 1$ is prime for all $n \ge 0$? I believe I see that $a_n = 2^n(a_0+1) - 1$ but am somewhat uncertain where to proceed afterwards. I am a complete beginner at number theory and would appreciate it if someone could point me in the right direction--surely there is some obvious argument I am missing. I have two passports/nationalities. How do I use them when I travel? Java Round up Any Number Returning anonymous functions from lapply - what is going wrong? TikZ: What EXACTLY does the the |- notation for arrows do? I am currently trying to work out how the perpendicular arrows  work, and I fail.  Taking:  \draw [arrow] (node1) -- node[sloped, above] {Caption} (node1 |- node2.north west);   I suspected that the notation meant: Draw an arrow from node 1, to the north-west corner of  node 2. Make the arrow perpendicular to node 1.  Further attempts to draw arrows told me: No, that's not it. I have sadly failed to figure out what exactly the notation is supposed to be doing though! Is there any "explanation for dummies" that will lead me to understand what exactly    node1 |-   Is supposed to do?  Thanks! What is the difference in meaning of "frustrated at" and "frustrated with" used in sentences like     He is frustrated with me   or      He is frustrated at me   When is each of these sentences above are used? Visual Studio: How to break on handled exceptions? I would like Visual Studio to break when a handled exception happens (i.e. I don't just want to see a "First chance" message, I want to debug the actual exception).  e.g. I want the debugger to break at the exception:  try {    System.IO.File.Delete(someFilename); } catch (Exception) {    //we really don't care at runtime if the file couldn't be deleted }   I came across  notes for Visual Studio.NET:     1) In VS.NET go to the Debug Menu >>   "Exceptions..." >> "Common Language   Runtime Exceptions" >> "System" and   select "System.NullReferenceException"      2) In the bottom of that dialog there   is a "When the exception is thrown:"   group box, select "Break into the   debugger"       3) Run your scenario. When the   exception is thrown, the debugger will   stop and notify you with a dialog that   says something like:              "An exception of type "System.NullReferenceException" has   been thrown.              [Break] [Continue]"       Hit [Break]. This will put you on the   line of code that's causing the   problem.   But they do not apply to Visual Studio 2005 (there is no Exceptions option on the Debug menu).  Does anyone know where the find this options dialog in Visual Studio that the "When the exception is thrown" group box, with the option to "Break into the debugger"?  Update: The problem was that my Debug menu didn't have an Exceptions item. I customized the menu to manually add it.