c# - SQL CLR stored procedure for encryption -


background: have ssis package loads profile data system , creates corresponding profiles , membership users in system b. system b uses custom asp.net membership provider must able decrypt passwords generated ssis package. i've created clr stored procedures salt generation , encryption used ssis package.

problem: in order encrypted passwords decryptable asp.net membership provider need set machinekey used clr stored procedures. have no idea how this, or if it's possible.

i used reflector pull out required encryption code system.membership dll. after bit of refactoring looks this:

private static byte[] performencryption(byte[] input, bool encryptflag) {     if (input == null)         return null;      byte[] inputbuf = input;     byte[] outputbuf;      try     {         using (memorystream targetstream = new memorystream())         using (symmetricalgorithm algo = symmetricalgorithm.create())         using (icryptotransform cryptotransform = createcryptotransform(algo, encryptflag))         using (cryptostream cryptostream = new cryptostream(targetstream, cryptotransform, cryptostreammode.write))         {             int start = 0;             int length = input.length;              // write input buffer cryptostream passing byte stream through cryptotransform             cryptostream.write(inputbuf, start, length);             cryptostream.flushfinalblock();             outputbuf = targetstream.toarray();         }     }     catch (exception ex)     {         throw new invalidoperationexception("unable " + (encryptflag ? "en" : "de") + "crypt data. see inner exception more detail.", ex);     }     return outputbuf; } 

the problem symmetricalgorithm.create() creates default symmetric algorithm init vectors defined machinekey.

any appreciated. also, please let me know if there better/different approach might easier.

thanks.

anyway, take accout this:

throw new invalidoperationexception(string.format("unable {0}crypt data. see inner exception more detail.", encryptflag ? "en" : "de"), ex); 

which rather readable. isn't it?

and thing - using blocks can nested, no additional indent required.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -