1
0
mirror of https://github.com/bitwarden/server synced 2026-02-18 18:33:29 +00:00
Files
server/util/Seeder/Factories/SecureNoteCipherSeeder.cs
2026-02-17 07:42:53 +01:00

49 lines
1.5 KiB
C#

using Bit.Core.Vault.Entities;
using Bit.Core.Vault.Enums;
using Bit.Seeder.Models;
namespace Bit.Seeder.Factories;
internal static class SecureNoteCipherSeeder
{
internal static Cipher Create(
string encryptionKey,
string name,
Guid? organizationId = null,
Guid? userId = null,
string? notes = null)
{
var cipherView = new CipherViewDto
{
OrganizationId = organizationId,
Name = name,
Notes = notes,
Type = CipherTypes.SecureNote,
SecureNote = new SecureNoteViewDto { Type = 0 }
};
var encrypted = CipherEncryption.Encrypt(cipherView, encryptionKey);
return CipherEncryption.CreateEntity(encrypted, encrypted.ToSecureNoteData(), CipherType.SecureNote, organizationId, userId);
}
internal static Cipher CreateFromSeed(
string encryptionKey,
SeedVaultItem item,
Guid? organizationId = null,
Guid? userId = null)
{
var cipherView = new CipherViewDto
{
OrganizationId = organizationId,
Name = item.Name,
Notes = item.Notes,
Type = CipherTypes.SecureNote,
SecureNote = new SecureNoteViewDto { Type = 0 },
Fields = SeedItemMapping.MapFields(item.Fields)
};
var encrypted = CipherEncryption.Encrypt(cipherView, encryptionKey);
return CipherEncryption.CreateEntity(encrypted, encrypted.ToSecureNoteData(), CipherType.SecureNote, organizationId, userId);
}
}