Как ответ Visual Vincent, ICryptoTransform не инициализируется с помощью «= new ICryptoTransform ()», но с использованием функции CreateEncryptor объекта алгоритма шифрования, такого как объект RijndaelManaged
Полный код следует, фиксируя выше проблемы использования интерфейса, однако этот код не работает полностью. Функция дешифрования не будет возвращать тот же самый открытый текст, что и в функцию шифрования по неизвестным причинам.
Текущий вывод консоли:
MyConsoleApplication.exe
Encrypting plaintext 'SALUT'
Output is : D9ehMNg+i+5/ZFVakNwSyQ==
Decrypting cyphertext 'D9ehMNg+i+5/ZFVakNwSyQ=='
Output is : NU??
>??,♫?#?4?q?
Код:
Imports System.Data.SqlClient
Imports System.IO
Imports System.Security.Cryptography
Public Module MyApplication
Public Sub Main()
Dim KEY_128 As Byte() = {42, 1, 52, 67, 231, 13, 94, 101, 123, 6, 0, 12, 32, 91, 4, 111, 31, 70, 21, 141, 123, 142, 234, 82, 95, 129, 187, 162, 12, 55, 98, 23}
Dim IV_128 As Byte() = {234, 12, 52, 44, 214, 222, 200, 109, 2, 98, 45, 76, 88, 53, 23, 78}
dim plaintext as string = "SALUT"
dim cyphertext as string, plaintext2 as string
cyphertext = myEncrypt(plaintext,KEY_128 , IV_128)
plaintext2 = myDecrypt(cyphertext,KEY_128 , IV_128)
System.Console.Write("Encrypting plaintext '" & plaintext & "'" & vbcrlf & "Output is : " & cyphertext & vbcrlf)
System.Console.Write("Decrypting cyphertext '" & cyphertext & "'" & vbcrlf & "Output is : " & plaintext2 & vbcrlf)
End Sub
public function myEncrypt(plaintext as string,KEY_128 As Byte(),IV_128 As Byte()) as string
dim enc As System.Text.UTF8Encoding = new System.Text.UTF8Encoding()
enc = New System.Text.UTF8Encoding
Dim symmetricKey As RijndaelManaged = New RijndaelManaged()
symmetricKey.Mode = CipherMode.CBC
dim encryptor As ICryptoTransform
encryptor = symmetricKey.CreateEncryptor(KEY_128, IV_128)
Dim memoryStream As MemoryStream = New MemoryStream()
Dim cryptoStream As CryptoStream = New CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)
cryptoStream.Write(enc.GetBytes(plaintext), 0, plaintext.Length)
cryptoStream.FlushFinalBlock()
return Convert.ToBase64String(memoryStream.ToArray())
memoryStream.Close()
cryptoStream.Close()
end function
public function myDecrypt(cyphertext as string,KEY_128 As Byte(),IV_128 As Byte()) as string
dim enc As System.Text.UTF8Encoding = new System.Text.UTF8Encoding()
enc = New System.Text.UTF8Encoding
Dim symmetricKey As RijndaelManaged = New RijndaelManaged()
symmetricKey.Mode = CipherMode.CBC
dim decryptor As ICryptoTransform
decryptor = symmetricKey.CreateEncryptor(KEY_128, IV_128)
Dim cypherTextBytes As Byte() = Convert.FromBase64String(cyphertext)
Dim memoryStream As MemoryStream = New MemoryStream(cypherTextBytes)
Dim cryptoStream As CryptoStream = New CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)
Dim plainTextBytes(cypherTextBytes.Length) As Byte
Dim decryptedByteCount As Integer = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length)
memoryStream.Close()
cryptoStream.Close()
return enc.GetString(plainTextBytes, 0, decryptedByteCount)
end function
End Module
Как дано объяснением здесь . Вы можете выполнить действие сброса, щелкая вкладку следующим образом:
import { StackActions, NavigationActions } from 'react-navigation';
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Profile' })],
});
this.props.navigation.dispatch(resetAction);
Таким образом, вы должны сделать что-то вроде:
tabBarOnPress{() => StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Screen1' })],
})};