【发布时间】:2015-03-11 21:00:47
【问题描述】:
我正在寻找与以下等效的 C# 代码
CREATE OR REPLACE
FUNCTION aes_encrypt(
plaintext IN VARCHAR2,
cryptokey IN VARCHAR2) -- key is expected to be 32 bytes
RETURN VARCHAR2
IS
v_varchar2 VARCHAR2(4000) := NULL; -- stores the encrypted data that will be returned
BEGIN
IF (cryptokey IS NULL OR LENGTH(cryptokey) <> 32) THEN
RAISE_APPLICATION_ERROR(-20001,'cryptokey must not be null and must be 32 bytes');
END IF;
IF (plaintext IS NOT NULL) THEN
v_varchar2 := rawtohex (
DBMS_CRYPTO.ENCRYPT (
src => UTL_I18N.STRING_TO_RAW (plaintext),
typ => DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5,
KEY => UTL_I18N.STRING_TO_RAW (cryptokey)
));
END IF;
RETURN v_varchar2;
END aes_encrypt;
我显然在 System.Security 命名空间中找到了这些东西(如 https://msdn.microsoft.com/en-us/library/system.security.cryptography.aes%28v=vs.110%29.aspx),但我不确定如何制作 IV 和密钥。
【问题讨论】:
标签: c# oracle encryption aes