protected string decrypt(IChannelHandlerContext ctx, EncryptedBytes encryptedString) { if (!encryptionKeyHolder.isEncryptionKeyRegistered(ctx, ctx.Channel)) { throw new ArgumentException("No secret key available"); } var secretKey = encryptionKeyHolder.getSecretKey(ctx, ctx.Channel); if (secretKey == null) { throw new ArgumentException("Secret key is null"); } var decryptedJson = EncryptionUtil.decrypt(encryptedString, secretKey, charset); return(decryptedJson); }
// jsc shall auto rethrow java methods that throw! // async rewriter causes issues for javac otherwise? //public async Task<EncryptedBytes> Encrypt(byte[] data) public Task<EncryptedBytes> Encrypt(byte[] data) { Console.WriteLine("enter Encrypt"); var value = default(EncryptedBytes); try { var rsaCipher = Cipher.getInstance("RSA"); //Encrypt rsaCipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic()); var encByte = (byte[])(object)rsaCipher.doFinal((sbyte[])(object)data); value = new EncryptedBytes(encByte); } catch { throw; } return value.AsResult(); }
//public async Task<byte[]> Decrypt(EncryptedBytes data) public Task<byte[]> Decrypt(EncryptedBytes data) { Console.WriteLine("enter Decrypt"); var value = default(byte[]); try { var rsaCipher = Cipher.getInstance("RSA"); //Decrypt rsaCipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate()); value = (byte[])(object)rsaCipher.doFinal((sbyte[])(object)data.bytes); } catch { throw; } return value.AsResult(); }
public async Task<byte[]> Decrypt(EncryptedBytes data) { Console.WriteLine("enter Decrypt"); return RSA.Decrypt(data.bytes, fOAEP: false); }